preg_replace all spaces

后端 未结 5 412
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-03 20:28

I\'m trying to replace all spaces with underscores and the following is not working:

$id = \"aa aa\";
echo $id;
preg_replace(\'/\\s+/\', \'_\', $id);
echo $i         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 20:43

    We need to replace the space in the string "aa aa" with '_' (underscore). The \s+ is used to match multiple spaces. The output will be "aa_aa"

    
    

提交回复
热议问题