使用php在html网页上计数单词
发布时间:2020-12-13 16:41:04 所属栏目:PHP教程 来源:网络整理
导读:我需要一个 PHP脚本,它接收一个网页的URL,然后回应一个单词被提及多少次. 例 这是一个通用的HTML页面: htmlbodyh1 This is the title /h1p some description text here,bthis/b is a word. /p/body/html 这将是PHP脚本: ?phphtmlurl="generichtml.com";the
我需要一个
PHP脚本,它接收一个网页的URL,然后回应一个单词被提及多少次.
例 这是一个通用的HTML页面: <html> <body> <h1> This is the title </h1> <p> some description text here,<b>this</b> is a word. </p> </body> </html> 这将是PHP脚本: <?php htmlurl="generichtml.com"; the script here echo(result); ?> 所以输出将是这样的表: WORDS Mentions This 2 is 2 the 1 title 1 some 1 description 1 text 1 a 1 word 1 这就像搜索机器人在上网时所做的那样,所以,有什么想法,如何开始,甚至更好,你有一个PHP脚本已经这样做了吗?
从您的字符串中删除所有HTML标记后,下面的一行将执行不区分大小写的字数.
Live Example print_r(array_count_values(str_word_count(strip_tags(strtolower($str)),1))); 要获取页面的源代码,可以使用cURL或file_get_contents() $str = file_get_contents('http://www.example.com/'); 从内到外: >使用strtolower()使所有小写. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |