我想要得到的内容(包括所有的CSS,链接工作等),这是在<div id="some-content"></div>
获取来自网页用的preg_match的具体内容
preg_match("/<div id=\'some-content\'>(.*)<\/div>/m", file_get_contents('www.xxx.com'), $output);
print_r ($output);
但它返回空数组: Array ()
出了什么问题? preg_match
或网页有问题吗?
如果你真的想与xxx.com(一个色情网站btw)一起工作,简单的答案是没有一个ID为“some-content”的div,因此你得到一个空数组。在这种情况下,我们鼓励您将URL更改为example.com(这是任何URL示例的官方URL)。尽管如此,答案可能是没有这样的div,或者它不会以这种确切的语法出现。您可以更可靠地使用HTML Parser刮取HTML。请参阅http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php – Gordon 2012-02-23 13:37:37
没有办法正确计算所有可能的内容,您应该使用HTML解析器,例如。 [PHP的常见问题](http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php) – scibuff 2012-02-23 12:50:14