Php 数组中的substr\u计数

Php 数组中的substr\u计数,php,arrays,count,substr,Php,Arrays,Count,Substr,我试图在强标记中搜索关键字 我为标签生成了一个数组,显示为: Array ( [0] => Array ( [0] => seo agency in london [1] => seo agency in london [2] => seo consultant in london [3] => seo consultant in lon

我试图在强标记中搜索关键字

我为标签生成了一个数组,显示为:

        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));
function substr\u count\u数组($haystack,$pinder){
$count=0;
foreach($针作为$子字符串){
$count+=substr\u count($haystack,$substring);
}
返回$count;
}
$matchPattern7='/]]*>(.*?/');
preg_match_all($matchPattern7,$content,$foundIt7);
echo substr_count_数组(strtolower($foundIt7),strtolower($keyword));
供参考

$keyword=seo

我得了零分,有人能帮我吗?感谢您对我进行了测试并对我有效:
function substr_count_array( $haystack, $needle ) {
$count = 0;
foreach ( $haystack as $substring) {
foreach($substring as $string)
{
$count += substr_count($string, $haystack);
}
}
return $count;
}
$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

抱歉,您需要在第1个循环中使用$haystack,恐怕仍然是0。非常感谢您的输入思想使用而不是一些会损坏的正则表达式。@PeeHaa谁说他没有使用DomDocument来获取
标记的内容?我完全支持使用DomDocument解析HTML,但这个问题不能单靠DomDocument来解决。@BerryLangerak这只是一个建议,否则它会出现在答案部分:)嗨,伙计们,谢谢你们的光临。我正在使用简单的HTMLDOM生成结果。@BerryLangerak因为我在OPs问题中看到了这个东西,也许<代码>$matchPattern7='/]*)*>(*?/”。顺便说一句,我从来没有说过这能解决问题。嗨,最后一位,谢谢你的意见。在不必指定数组名称的情况下,如何执行此操作。即。。preg_match_all($matchPattern7,$content,$foundIt7)正在生成数组,每次都会不同,因此我不知道数组上生成了什么,但需要在数组上搜索一组关键字。如果你能给我发电子邮件那就太好了?我的代码已经做到了,只需注释掉打印内容,然后使用preg\u match\u all($matchPattern7,$content,$foundIt7)来填充你的$foundIt7数组。然后简单地执行echo substr_count_array($foundIt7,strtolower($keyword))来计算匹配项。如果您想将strtolower应用于阵列,则需要从循环中执行。这非常有效,谢谢!如果你想帮我做一些其他的自由职业者的工作,请发电子邮件给我詹姆斯·戴德曼(在gmail.com上)