php抓取新闻

WBOY
WBOYOriginal
2016-06-23 13:34:501412browse

我要抓取网页的一部分新闻内容并显示在自己的前台页面上,请问该怎么做呢?
比如在网易上跟家居有关的新闻

$url = "http://home.163.com";
$contents = file_get_contents($url);
//如果出现中文乱码使用下面代码
//$getcontent = iconv("gb2312", "utf-8",$contents);
echo $contents;
?>


上面这代码只是获取全部页面吧


回复讨论(解决方案)

正则匹配或者用simple_html_dom
看你要哪些内容

正则匹配或者用simple_html_dom
看你要哪些内容



就是定向抓取几个新闻,有示例么

preg_match_all('/

()/',$contents,$m);
echo "
";  <br> print_r($m[1]);  <br> echo "
";

preg_match_all('/

()/',$contents,$m);
echo "
";   <br> print_r($m[1]);   <br> echo "
";

感谢回答,如果要用中文关键字匹配呢

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP如何调用C#编写的程序Next article:=