David
David

Reputation: 59

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 replace string mantain lowercases and upercases of the original string?

Thanks, sorry for my english

Upvotes: 0

Views: 111

Answers (1)

user142162
user142162

Reputation:

This is easily done with preg_replace.

$string = preg_replace('/world/i', '<strong>$0</strong>', $string);

Upvotes: 4

Related Questions