与php中的子字符串进行字符串比较?

时间:2014-04-21 11:01:37

标签: php string

数组中的字符串为ATA Report of 7th Apr 2014, ATA Report of 17th Apr 2014, ATA Report of 27th Apr 2014

我有子字符串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.........

}

1 个答案:

答案 0 :(得分: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;
    }
}

另外,strpos()你以错误的方式使用它......大海捞针应先出现,接着是针。