2

強力なタグ内のキーワードを検索しようとしています。

次のように表示されるタグの配列を作成しました。

        Array
        (
        [0] => Array
        (
        [0] =>  seo agency in london
        [1] => seo agency in london
        [2] => seo consultant in london
        [3] => seo consultant in london
        [4] => seo experts in london
        )

        [1] => Array
        (
        [0] =>  seo agency in london
        [1] => seo agency in london
        [2] => seo consultant in london
        [3] => seo consultant in london
        [4] => seo experts in london
        )

        )

そして、この場合は「seo」というキーワードを検索したい

使ってます:

function substr_count_array( $haystack, $needle ) {
$count = 0;
foreach ($needle as $substring) {
$count += substr_count( $haystack, $substring);
}
return $count;
}
$matchPattern7 = '/<strong(?:"(?:[^\\\"]|\\\.)*"|\'(?:[^\\\\\']|\\\.)*\'|[^\'">])*>(.*?)<\/strong>/';
preg_match_all($matchPattern7, $content, $foundIt7);
echo substr_count_array(strtolower($foundIt7), strtolower($keyword));

参考のために..

$ keyword = seo

私はゼロになっています、誰か助けてもらえますか?ありがとう

4

2 に答える 2

0
function substr_count_array( $haystack, $needle ) {
$count = 0;
foreach ( $haystack as $substring) {
foreach($substring as $string)
{
$count += substr_count($string, $haystack);
}
}
return $count;
}
于 2012-10-19T09:17:12.963 に答える
0

テストされ、私のために動作します:

$foundIt7=array();
$foundIt7[1]=array(0 => ' seo agency in london',
        1 => 'seo agency in london',
        2 => 'seo consultant in london',
        3 => 'seo consultant in london',
        4 => 'seo experts in london');
print_r($foundIt7[1]);


function substr_count_array( $haystackAr, $needle ) {
$count = 0;
foreach ($haystackAr as $haystack) {
$count += substr_count( $haystack, $needle);
}
return $count;
}

echo substr_count_array($foundIt7[1],'seo');//returns 5
于 2012-10-19T09:46:56.843 に答える