1
I have the xml example:
<Listings>
<Listing>
<Title>Nome</Title>
<Details>
<Description>
dados
</Description>
</Details>
<Media>
<Item medium="image">
https://site.com.br/PM.jpeg
</Item>
<Item medium="image">
https://site.com.br/PM.jpeg
</Item>
<Item medium="image">
https://site.com.br/PM.jpeg
</Item>
</Media>
</Listing>
<Listing>
<Title>Nome</Title>
<Details>
<Description>
dados
</Description>
</Details>
<Media>
<Item medium="image">
https://site.com.br/PM.jpeg
</Item>
<Item medium="image">
https://site.com.br/PM.jpeg
</Item>
<Item medium="image">
https://site.com.br/PM.jpeg
</Item>
</Media>
</Listing>
</Listings>
I’m reading with the function simplexml_load_file
, data reading occurs normally, my problem is how to read all items within the node <Media>
I tried it this way:
foreach($xml->Listings as $registro):
echo 'Título: ' . $registro->Listing->Title . '<br>';
foreach($registro->Listing->Media as $item):
echo 'Imagem: ' . $item->Item . '<br>';
endforeach;
endforeach;
Dear, it’s okay that you chose an answer "try this", which does not explain anything, is your choice and I cannot and will not attempt to interfere... yet I have added an extra explanation about the use of Trim to remove the unnecessary extra spaces: https://answall.com/a/326045/3635. which may be useful to you.
– Guilherme Nascimento