0

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?

Strawberry
  • 62,326
  • 55
  • 143
  • 194

1 Answers1

6

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.

Community
  • 1
  • 1
ryeguy
  • 63,287
  • 56
  • 190
  • 257