我一直在寻找类似的问题,但没有找到有类似问题或可能的解决方案的人。我有 preg_match_all 函数,它找到我 5 个匹配项并将它们返回到数组中。如何计算数组中的字符串?
preg_match_all("/\)\">(.*?)<\/a>/s",$value,$counter);
here is var_dump(counter[1]):
array (size=1)
0 => string 'word1' (length=..)
array (size=1)
0 => string 'word2' (length=..)
array (size=1)
0 => string 'word3' (length=..)
array (size=1)
0 => string 'word4' (length=..)
array (size=1)
0 => string 'word5' (length=..)
正如您所看到的,它返回了 5 个匹配项,但我无法用array_count_values
,打印该数字count()
……我尝试过 imploding then 以获取字符串,但也count()
无法正常工作。
count($counter[1]) returns me ->
int 1
int 1
int 1
int 1
int 1
我需要获得比赛的数量,我没有更多的想法,所以任何事情都非常受欢迎。
更新:这里是 var_dump($value);
string '<h2><a href="javascript:Organigram.toggle('organigram_section_29')">word1</a></h2><div class="show"><p class="nums"><span class="phone">03 839 11 00</span></p>' (length=170)
string '<h2><a href="javascript:Organigram.toggle('organigram_section_35')">word2</a></h2><div class="show"><p class="nums"><span class="phone">03 839 12 00</span><span class="fax">03 839 12 18</span><span class="email email-mod"><a title="info@golte.si" href="mailto:info@golte.si"><img alt='info@golte.si' src='Txt2Image.ashx?AAARAAcASQAAAB0AEgAGADMAEwAGAB8AAAAMAF0ABwAAAFUAGQAGABcAEQBUAAAAAAAQAB8AEQANAFUAEgAGAB0AAABUADIABgAAABIAGABSAEIAQABSAAMADABSAFAARQAtAEcARQBeADYATwALABwAGAANAEMARABZAEMARQBdADIARQA=' /></a></s'
...(长度=938)`
string '<h2><a href="javascript:Organigram.toggle('organigram_section_51')">word3</a></h2><div class="show"><p class="nums"><span class="phone">03 839 12 12</span></p>' (length=162)
string '<h2><a href="javascript:Organigram.toggle('organigram_section_56')">word4</a></h2><div class="show"><p class="nums"><span class="phone">03 839 12 14</span></p>' (length=168)
string '<h2><a href="javascript:Organigram.toggle('organigram_section_61')">word5</a></h2><div class="show"><p class="nums"><span class="phone">03 839 61 28</span></p>' (length=162)