str_replace for distinct word

后端 未结 2 849
感情败类
感情败类 2021-01-28 10:49

suppose I have $str=\"nikparsa neginnikparsa somenikparsa\" when I use

$str= str_replace(\'nikparsa\', \'nik parsa\', $str);
echo $str;
相关标签:
2条回答
  • 2021-01-28 11:19

    Well, if you really don't want to use preg_replace, then:

    substr( str_replace( ' stackoverflow ', '  do you see the apples?  ', " $str "), 1, -1 );
    

    Read the comments about its limitations :)

    0 讨论(0)
  • 2021-01-28 11:25

    Use preg_replace:

    $str = preg_replace('/\bnikparsa\b/i', 'nik parsa', $str);
    
    0 讨论(0)
提交回复
热议问题