Replacing Spaces with Underscores

前端 未结 12 570
北海茫月
北海茫月 2020-11-30 20:14

I have a PHP Script that users will enter a name like: Alex_Newton,

However, some users will use a space rather than an underscore, so my question is:

12条回答
  •  盖世英雄少女心
    2020-11-30 21:14

    str_replace - it is evident solution. But sometimes you need to know what exactly the spaces there are. I have a problem with spaces from csv file.

    There were two chars but one of them was 0160 (0x0A0) and other was invisible (0x0C2)

    my final solution:

    $str = preg_replace('/\xC2\xA0+/', '', $str);
    

    I found the invisible symbol from HEX viewer from mc (midnight viewer - F3 - F9)

提交回复
热议问题