PHP中的单页Web爬网

时间:2011-06-09 22:33:58

标签: php html webpage phpcrawl

我是PHP的新手。有人可以帮我弄清楚如何抓取单个html页面并打印该页面源代码中的所有单词吗?

2 个答案:

答案 0 :(得分:1)

您的问题不是很清楚,但您需要下载页面(使用cURL或PHP的文件功能)并以某种方式处理文件。这是一个基本的解决方案:

echo strip_tags(file_get_contents('http://www.google.com'));

答案 1 :(得分:1)

$words = explode(" ", strip_tags(file_get_contents("www.example.com"));
function trim_and_print(&$value) 
{ 
    trim($value);
    if(strlen($value > 3) 
        echo $value;
}

array_walk($words, 'trim_and_print');

这应该打印长度为>的单词3.感谢file_get_contents的moteutsch