php抓取新闻

WBOY
Release: 2016-06-23 13:34:50
Original
1391 people have browsed it

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

$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 "
Copy after login
";

preg_match_all('/

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template