PHP Word Replacing Issue -
actually problem shouldn’t hard searched in stackoverflow couldn’t find works want or can understand. here’s i’m asking for: image there text like: “hi today temperature high” i’d replace string “hi” “al” don’t want word high replaced “algh”. know need use preg_replace function couldn’t make work.
ps: if can show solution array too, more satisfied. there’s array of strings changed , there’s array of strings changed as.
appreciate :)
you can use regex \b make work.
$string = 'hi today temperature high'; $pattern = '/\bhi\b/'; $replacement = 'al'; echo preg_replace($pattern, $replacement, $string);
\b assert position @ word boundary (^\w|\w$|\w\w|\w\w)
Comments
Post a Comment