View Full Version : str_replace() problem

07-21-2012, 12:11 AM
hi. I have some string:

$string = "PHP is the best!";
, then I have another string that I get from user:

$_POST['q'] = "php";.
So I found a match. Now I display $string and replace it like this

$string = str_replace($_POST['q'], "<b>".$_POST['q']."</b>", $string);.
So I want to make the searched text bold in the $string. But it works only if $_POST['q'] is "PHP" not if "php" or "Php". Is there any way to fix this?

07-21-2012, 01:10 AM
Yep, you can use str_ireplace for insensitive searches.
Regex is also an option as well, although when you know exactly what you are searching for and what you are replacing with then you should use str_replace family.