Search the Community
Showing results for tags 'empty key'.
-
I am scrapping an xml feed with the file_get_contents() and explode() function. Some the xml nodes do not exsist; so I am getting an inconsistant array from a for() loop. What would be the best way to keep an array key, created from an explode() function; empty, if there is no corresponding xml node to be scrapped? Currently, when I use the code below; I get all the node's content (that exsisit within the xml document) at the top and then, at the bottom; I get all the empty node's content or basically a empty/blank area. What I am getting is this: pic1.jpg<br/> pic3.jpg<br/> pic5.jpg<br/> <br/> <br/> And... what I want to get is this: pic1.jpg<br/> <br/> pic3.jpg<br/> <br/> pic5.jpg<br/> Here is my XML code (syndicate.xml): <?xml version="1.0" encoding="iso-8859-1"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:enc="http://purl.oclc.org/net/rss_2.0/enc#" xmlns:ev="http://purl.org/rss/1.0/modules/event/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:admin="http://webns.net/mvcb/" > <item> <enc:enclosure resource="pic1.jpg" type="image/jpeg"/> </item> <item> </item> <item> <enc:enclosure resource="pic3.jpg" type="image/jpeg"/> </item> <item> </item> <item> <enc:enclosure resource="pic5.jpg" type="image/jpeg"/> </item> </rdf:RDF> And... here is my PHP code: <?php $rss = file_get_contents("syndicate.xml"); $img = explode("enclosure resource=\"",$rss); for($key = 0; $key < 5; $key++){ $img2 = explode("\"",$img[$key+1]); echo $img2[0]."<br/>\n"; } ?>