tags:

views:

55

answers:

1

I need to grab the list of names and descriptions of a website for indexing purposes. How can I do this using PHP? I would think I would have to use DOM correct?

+6  A: 

Yes, that is the best way. I would recommend using PHP Simple HTML DOM Parser. You can do spiffy stuff like this:

// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

// Find all images
foreach($html->find('img') as $element)
       echo $element->src . '<br>';

// Find all links
foreach($html->find('a') as $element)
       echo $element->href . '<br>'; 

Whatever you do, do not try parsing HTML with regular expressions.

ryeguy