Replacing Spaces with Underscores

前端 未结 12 556
北海茫月
北海茫月 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:00

    You can also do this to prevent the words from beginning or ending with underscores like _words_more_words_, This would avoid beginning and ending with white spaces.

    $trimmed = trim($string); // Trims both ends
    $convert = str_replace('', '_', $trimmed);
    

提交回复
热议问题