I would like to replace just complete words using php
Example :
If I have
$text = "Hello hellol hello, Helloz";
and I use
$newtext = str_replace("Hello",'NEW',$text);
The new text should look like
NEW hello1 hello, Helloz
PHP returns
NEW hello1 hello, NEWz
Thanks.
You want to use regular expressions. The
\bmatches a word boundary.If
$textcontains UTF-8 text, you’ll have to add the Unicode modifier “u”, so that non-latin characters are not misinterpreted as word boundaries: