PHP mb_ereg_replace not replacing while preg_replace works as intended

前端 未结 3 1312
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 00:29

I am trying to replace in a string all non word characters with empty string expect for spaces and the put together all multiple spaces as one single space.

Followin

3条回答
  •  长发绾君心
    2021-01-19 00:49

    mb_ereg_replace doesn't use separators. You may or may not also have to specify the encoding before.

    mb_regex_encoding("UTF-8");
    //regex could also be \W
    $cleanedString = mb_ereg_replace('[^\w]', ' ', $name);
    $cleanedString = mb_ereg_replace('\s+', ' ', $cleanedString);
    

提交回复
热议问题