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)

https://regex101.com/r/wdqtmp/2


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -