Blu*_*lue 1 php count preg-match-all preg-match
我一直在寻找类似的问题,但没有发现任何人有类似的问题或可能的解决方案.我有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=..)
Run Code Online (Sandbox Code Playgroud)
正如你所看到的那样,它返回了我的5场比赛,但是我不能打印那个数字array_count_values,count()...我已经尝试了爆炸,然后得到字符串,但也count()不会工作.
count($counter[1]) returns me ->
int 1
int 1
int 1
int 1
int 1
Run Code Online (Sandbox Code Playgroud)
我需要获得一些比赛,我没有更多的想法,所以任何事情都是非常受欢迎的.
更新:这是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)
小智 6
preg_match_all本身返回完整模式匹配的数量(可能为零),如果发生错误则返回FALSE.
$number = preg_match_all("/\)\">(.*?)<\/a>/s",$value,$counter);
Run Code Online (Sandbox Code Playgroud)