是的,这是最好的方式.我建议使用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.