javawizkid Posted August 5, 2011 Share Posted August 5, 2011 Hey, not sure what I'm doing wrong as nothing is displayed in the echo. <?php $doc = new DOMDocument(); $doc->load('http://feeds.feedburner.com/148apps_newest'); $arrFeeds = array(); foreach ($doc->getElementsByTagName('description') as $node) { $itemRSS = array ( 'image' => $node->getElementsByTagName('img')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); } //print_r($arrFeeds); for ($i=0;$i<=40;$i++) { echo $arrFeeds[$i][image]; echo ("<br/><br/>"); } ?> print_r($arrFeeds); outputs blank array items... Hmm Thanks Quote Link to comment https://forums.phpfreaks.com/topic/243941-html-parsing/ Share on other sites More sharing options...
@ Posted August 5, 2011 Share Posted August 5, 2011 Add some debug lines inside your foreach loop to check that it is behaving as expected. But at a glance id say that either the array_push function isn't getting called or an error occurs before the processor reaches that line of code Quote Link to comment https://forums.phpfreaks.com/topic/243941-html-parsing/#findComment-1252577 Share on other sites More sharing options...
AyKay47 Posted August 5, 2011 Share Posted August 5, 2011 make sure that error_reporting is set to E_ALL and check your error.log for errors, is turn display_errors ON Quote Link to comment https://forums.phpfreaks.com/topic/243941-html-parsing/#findComment-1252590 Share on other sites More sharing options...
javawizkid Posted August 5, 2011 Author Share Posted August 5, 2011 I changed the code to <?php require_once('simple_html_dom.php'); $html = file_get_html('http://feeds.feedburner.com/148apps_newest'); //echo $html; // Find all images foreach($html->find('img') as $element) echo $element->src . '<br>'; ?> to make it simple. It doesn't seem to like reading feeds. It can parse normal html websites like yahoo.com and outputs the image urls as desired. Why won't it parse the url above? Quote Link to comment https://forums.phpfreaks.com/topic/243941-html-parsing/#findComment-1252842 Share on other sites More sharing options...
kickstart Posted August 5, 2011 Share Posted August 5, 2011 Hi Looking at the source of the page you are grabbing I am not sure it is valid HTML Rather than having:- <img it has < All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/243941-html-parsing/#findComment-1252847 Share on other sites More sharing options...
javawizkid Posted August 6, 2011 Author Share Posted August 6, 2011 It wont read it even if I change it to < <?php require_once('simple_html_dom.php'); $html = file_get_html('http://feeds.feedburner.com/148apps_newest'); //echo $html; // Find all images foreach($html->find('<') as $element) echo $element->src . '<br>'; ?> Has it got anything to do with the fact it redirects the url to feed:// instead of http:// ? Quote Link to comment https://forums.phpfreaks.com/topic/243941-html-parsing/#findComment-1252940 Share on other sites More sharing options...
kickstart Posted August 6, 2011 Share Posted August 6, 2011 Hi Using a normal file_get_contents brings back the contents. Afraid I have no experience of simplehtmldom to suggest anything on that. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/243941-html-parsing/#findComment-1253336 Share on other sites More sharing options...
javawizkid Posted August 6, 2011 Author Share Posted August 6, 2011 What code should I use to grab the img urls then if is feed:// ? Quote Link to comment https://forums.phpfreaks.com/topic/243941-html-parsing/#findComment-1253351 Share on other sites More sharing options...
kickstart Posted August 6, 2011 Share Posted August 6, 2011 Hi Afraid I don't know. It works fine using file_get_contents, but I presume the html parser you are using requires the other function. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/243941-html-parsing/#findComment-1253353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.