0
I have a line of json code that comes from a variable and I want to list this json list to enter a database but I can’t read it.
$datesSite = file_get_contents('site');
$Puxa_titulo = explode('<div class="gallery-content item-gallery__wrapper" data-gallery-id="default" data-full-images="[' , $dadosSite );
$Titulo = explode(']">' , $Puxa_titulo[1] );
$json = $Titulo[0];
echo $json;
the site returns it:
{"src": "foto1.jpg", "w": "1200", " h ":" 900 "}, {" src ":" foto2.jpg "," w ":" 1200 "," h ":" 900 "}, {" src ":" foto3.jpg "," w ":" 1200 "," h ":" 900 "}, {" src ":" foto5.jpg "," w ":" 1200 "," h ":" 900 "}
I need to read this json list he tried to do this but it didn’t work
for($i = 0; $i < count($json); $i++) {
echo "<div>SRC: " . $json[$i]->{'src'} . "</div>";
echo "<div>w: " . $json[$i]->{'w'} . "</div>";
echo "<br />";
}
Have you already performed json_decode? To turn json into a possible object to use php.
– André Lins
I don’t know how to do this
– Leandro Ferreira
puts exactly what $json returns.
– André Lins
{"src": "foto1.jpg", "w": "1200", "h ":" 900 "}, {" src ":" foto2.jpg"," w ":" 1200"," h ":" 900 "}, {" src ":" foto3.jpg"," w ":" 1200"," h ":" 900 "}, {" src ":" foto5.jpg"," w ":" 1200"," h ":" 900 "}
– Leandro Ferreira
I posted an answer, try it there.
– André Lins