且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从HTML页面中提取文本块?

更新时间:2023-08-28 17:15:58

我使用phpQuery。你熟悉jQuery吗?他们共享相同的语法。你可能会担心安装一个新的库,但相信我这个库是值得的额外头顶

I use phpQuery. Are you familiar with jQuery? they share the same syntax. You might be concerned about installing a new library, but trust me this library is well worth the extra over head

然后你可以像这样访问它:

You can then access it like this:

foreach($doc->find('p') as $element){
   $element = pq($element);
   echo str_word_count($element->text());
}