0

指定した単語が Web ページに表示される回数を返すスクリプトが必要です。PHPでこれを行う方法を知っている人はいますか?コードは次のようになります。

<?php
$url="watever.com";
the script here
echo(result);
?>

Web ページ上のすべての単語が何回表示されるかを示すこの小さなビットはありますが、1 つの単語だけを変更する方法がよくわかりません。

$str = file_get_contents('http://www.example.com/');
print_r(array_count_values(str_word_count(strip_tags(strtolower($str)), 1)));
4

3 に答える 3

0

substr_countを探していると思います。

substr_count - 部分文字列の出現回数を数える

于 2013-04-16T00:17:51.010 に答える
0

substr_countを使用してみてください:

$result = (substr_count(strip_tags($str),"mycoolword"));
于 2013-04-16T00:18:24.980 に答える
0

preg_match の使用を検討してください - http://php.net/manual/en/function.preg-match.php

パラメータの 1 つは $matches です。これを渡すと、すべての一致がその配列に格納されるため、count($matches) を実行してカウントを取得できます。

PHP ページには良い例があります。

<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>
于 2013-04-16T00:18:33.033 に答える