我是 PHP 新手。有人可以帮我弄清楚如何抓取单个 html 页面并打印该页面源代码中的所有单词吗?
问问题
1431 次
2 回答
1
您的问题不是很清楚,但您需要下载页面(使用 cURL 或 PHP 的文件函数)并以某种方式处理文件。这是一个基本的解决方案:
echo strip_tags(file_get_contents('http://www.google.com'));
于 2011-06-09T22:38:49.633 回答
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 的单词。感谢 moteutsch for file_get_contents
于 2011-06-09T22:41:14.817 回答