regex - How do I get a particular word from a string in PHP? -


say have string, don't know contains. , want replace occurences of particular word or part of word formatted version of same word. example, have string contains "lorem ipsum" , want replace entire word contains "lo" "lorem can" end result "lorem can ipsum" if put string "loreal ipsum" through same function, result "loreal can ipsum". thanks

$str = preg_replace('/lo(\w*)/', 'lo$1 can', $str);

this replaces "lo" plus word characters "lo" + other characters + " can"

it replace "lo" "lo can" - if don't want this, change \w* \w+


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -