Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
看看这段代码 echo file_get_html('http://www.google.com)->plaintext;,它将从网站获取全部内容。所以,我的问题是如何获取有限的单词。假设它只会获取 180 个单词.. 任何想法?
echo file_get_html('http://www.google.com)->plaintext;
file_get_html 创建一个 DOM 对象,它需要完整的页面加载/解析,因此您不一定能按字符数抓取。但是,您可以启动文件处理程序并 fread 到一定数量的字节:
$fh = fopen('google.com'); $data = fread($fh,$length); fclose($fh);
或这个:
$data = substr(file_get_contents('google.com'),$start,$end);