Reputation: 23
For example I have a string : "This is a !thing"
How can I make it like this - "This is a !<b>thing</b>
"
Any help would be appreciated.
Thanks guys.
Upvotes: 2
Views: 61
Reputation: 781096
preg_replace('/!(\w+)/', '!<b>$1</b>', $string);
In the replacement string $n
is replaced with whatever matched n
th capture group in the regexp.
Upvotes: 3