如何判断字符串是否包含某些字符 如何判断字符串是否包含某些字符$str="modcss/img/h3_bg/h3_14_bg.png"判断$str里面是否包含 "h3_14_g.png" 这段字符串用什么函数?是不是必须用preg_match? preg_match好像只能正则匹配吧。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?php $str="modcss/img/h3_bg/h3_14_bg.png" ;if (strstr($str,"h3_14_bg.png")!=="false"){ echo strstr($str,"h3_14_bg.png");}?> 楼上正解!$str="modcss/img/h3_bg/h32_14_bg.png"; if(strpos($str,'h3_14_bg.png')) { echo "exists!"; }else { echo "not exists!"; } 另外的思路$str="modcss/img/h3_bg/h3_14_bg.png";echo (str_ireplace('h3_14_bg.png','',$str) != $str) ? 'exists!' : 'not exists!'; strpos要比strstr节省内存. 在php手册里面这样写的:注: If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos() instead. $str="modcss/img/h3_bg/h3_14_bg.png" ;$pos1 = strpos($str,'h3_14_bg.png'); The 7 floor is good answer. 一个奇怪的问题,可能与机制有关 THINKPHP 框架报:XML标签语法错误 : file="Public:header" 求助!!哪位帮忙解决一下有关session的问题!!谢谢 php中select的option自动改变的问题 能否通过php(函数)查看rpm信息???? 一个郁闷的session问题 这样的后台应怎样做? 有没有php版的网站生成工具? 请问怎样在mysql里查询指定时间段的内容 php mysql 一对多关系的数据查询求救 增加一下主键竟然错误 英文网站程序谁有?
$str="modcss/img/h3_bg/h3_14_bg.png" ;
if (strstr($str,"h3_14_bg.png")!=="false"){
echo strstr($str,"h3_14_bg.png");
}
?>
if(strpos($str,'h3_14_bg.png'))
{
echo "exists!";
}else
{
echo "not exists!";
}
$str="modcss/img/h3_bg/h3_14_bg.png";
echo (str_ireplace('h3_14_bg.png','',$str) != $str) ? 'exists!' : 'not exists!';
注: If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos() instead.
$pos1 = strpos($str,'h3_14_bg.png');