str_replace: Match whole word only

前端 未结 5 1118
后悔当初
后悔当初 2021-01-18 13:21

Since str_replace() matches \":Name\" two times in \":Name :Name_en\" I want to match the results for the whole word only. I wanted to switch to preg_repl

5条回答
  •  被撕碎了的回忆
    2021-01-18 14:15

    you can use space, to replace its common to find space between sentence words.

    $str = ":Name :Name_en";
    echo $str;
    
    // The final int limits the function to a single replace.
    $str = str_replace(':Name ', 'Test', $str);
    
    echo $str;
    

提交回复
热议问题