2014-04-21 107 views
1

字符串目前阵列ATA Report of 7th Apr 2014, ATA Report of 17th Apr 2014, ATA Report of 27th Apr 2014字符串与PHP中的子字符串比较?

我有子字符串中7th Apr 2014

我如何才能找到ATA Report of 7th Apr 2014位置

我甲肝像这样使用,但不是为我工作

$date = "7th Apr 2014" 
if (strpos("ATA Report of 7th Apr 2014", $date) !== false){ 
//my code......... 

} 
+0

你是什么意思“没为我工作”它应该工作得很好 – samayo

+0

@Simon_eQ,它不会正常工作,因为'strpos()'使用不当。 –

回答

1

您需要将它们循环。

<?php 
$arr=array("ATA Report of 7th Apr 2014", "ATA Report of 17th Apr 2014", "ATA Report of 27th Apr 2014"); 
foreach($arr as $k=>$v) 
{ 
    if(strpos($v,"7th Apr 2014") !== false) 
    { 
     echo "The position is $k"; 
     break; 
    } 
} 

此外,您正在以错误的方式使用它...干草堆应该先来,然后是针。

+0

我想找到“2014年4月7日”第一场比赛发生的地方.......... – Lipsa

+0

@ user3518270,这就是代码的作用。它返回位置0'2014年4月7日'是在数组的第一个位置。 –

+0

$ v =“2014年4月7日”;对 ? – Lipsa