How to replace substring with php with lower or upper character

I need to replace the substring with any string in upper or lower case

$sub = "STR";
$newsub="All-";
$str="Strstring";
$newstr=str_replace($sub,$rep,$str);
+4
source share
2 answers

You can use the str_ireplacePHP function as

$sub = "STR";
$newsub="All-";
$str="Strstring";
$newstr=str_ireplace($sub,$newsub,$str);

Fiddle

+5
source

You can also use preg_replace-

$sub = array('/STR/i');
$newsub="All-";
$str="Strstring";
echo $newstr=preg_replace($sub, $newsub, $str);

Output

All-All-ing
0
source

All Articles