php中字符串与子字符串的比较?
数组中的字符串为2014年4月7日的ATA报告、2014年4月17日的ATA报告、2014年4月27日的ATA报告 我有子字符串php中字符串与子字符串的比较?,php,string,Php,String,数组中的字符串为2014年4月7日的ATA报告、2014年4月17日的ATA报告、2014年4月27日的ATA报告 我有子字符串2014年4月7日 如何找到2014年4月7日的ATA报告 我曾经这样使用过,但没有为我工作过 $date = "7th Apr 2014" if (strpos("ATA Report of 7th Apr 2014", $date) !== false){ //my code......... } 你需要把它们循环一下 <?php $arr=array("
2014年4月7日
如何找到2014年4月7日的ATA报告
我曾经这样使用过,但没有为我工作过
$date = "7th Apr 2014"
if (strpos("ATA Report of 7th Apr 2014", $date) !== false){
//my code.........
}
你需要把它们循环一下
<?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;
}
}
你说“不为我工作”是什么意思?它应该只为我工作fine@Simon_eQ,它不会正常工作,因为没有正确使用strpos()
。@user3518270,这就是代码的作用。它返回位置0,因为2014年4月7日在数组的第一个位置。@user3518270,对不起,我修改了代码。你是对的。如果它对你有效,请接受并投票。谢谢:)