replace words of a string mantain lowercase and uppercase chars of original string
I have, for example, this string $string='Hello World, hello world';
I have a parameter in lowercase or uppercase and I need to replace all the equal words for <stong>word</strong>
If i try this:
$newstring=str_ireplace('world','<strong>world<s/trong>',$string);
The result are Hello world, hello world (lowercase w in the first word) is to be posssible repl开发者_JAVA技巧ace string mantain lowercases and upercases of the original string?
Thanks, sorry for my english
This is easily done with preg_replace.
$string = preg_replace('/world/i', '<strong>$0</strong>', $string);
精彩评论