0
I have an xml file, and I would like to bring to the page only one item of that file, in case I can bring all the items of a view only through the code
<?php
$feed = file_get_contents('https://brasil.elpais.com/rss/brasil/portada_completo.xml');
$rss = new SimpleXmlElement($feed);
//echo "<pre>"; print_r($rss);
foreach($rss->channel->item as $noticia) {
echo '<p><a href="'.$noticia->link.'" title="'. $noticia->title .'">'.$noticia->title.''.$noticia->description.'</a></p>';
}
?>
In case I don’t want to present all the items, I just want a specific part of XML, which is in the middle of the generated array, the print of the generated array is this:
in case I want to bring the [item][6] array, only I am not able to do this location, and I would also like to ask some way to integrate xmls, in case I have more than 1 I would like to insert the selected tags on the page. If you can help me I’m grateful.
In case show the first item tag of the first xml file, then show the first item tag of the second xml file, dps show the fourth item tag of the first xml file and so on.
Great super worked, I wanted to ask a question, inside the tag item, there is a tag [Enclosure] which is an array with 2 attributes like this: [Enclosure] => Array ( [0] => Simplexmlelement Object ( [@Attributes] => Array ( [url] => https://ep00.epimg.net/politica/imagenes/2018/07/11/actualidad/1531322308_202368_1531325055_miniatura_normal.jpg [length] => 26887 [type] => image/jpeg ) [1] => Simplexmlelement Object... ai with the same elements as above, only changes the [url] tag. and wanted to display the [Enclosure] tag’s Dice 1 and it shows me nothing.
– Bruno Clementin
@Brunoclementin edited the answer and put an example of how to take the attributes of Enclosure
– Guilherme Nascimento
too @Guilhermenascimento, I’m new to the programming world and you’ve been of great help, I’m extremely grateful for your help. , just one more thing, in case it shows me the http of the url, and not the image itself, know how to solve to show the image ?
– Bruno Clementin
@Brunoclementin like this
echo '<img src="', $enclosure->url,'">';
– Guilherme Nascimento
Sensational thank you very much!
– Bruno Clementin