Jump to content

HTML Parsing


javawizkid

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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:// ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.