如何使用PHP获取信息?

Str*_*rry 0 php

我需要获取网站的名称和描述列表以进行索引.我怎么能用PHP做到这一点?我想我必须使用DOM正确吗?

rye*_*guy 6

是的,这是最好的方式.我建议使用PHP Simple HTML DOM Parser.你可以做这样漂亮的东西:

// 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>'; 
Run Code Online (Sandbox Code Playgroud)

无论您做什么,都不要尝试使用正则表达式解析HTML.