我需要替换子字符串,无论这个字符串大写还是小写
$sub = "STR";
$newsub="All-";
$str="Strstring";
$newstr=str_replace($sub,$rep,$str);
你可以使用 PHP 的str_ireplace
函数作为
$sub = "STR";
$newsub="All-";
$str="Strstring";
$newstr=str_ireplace($sub,$newsub,$str);
小提琴
你也可以
使用preg_replace
-
$sub = array('/STR/i');
$newsub="All-";
$str="Strstring";
echo $newstr=preg_replace($sub, $newsub, $str);
输出
All-All-ing