作者:手机用户2502861125 | 来源:互联网 | 2020-12-02 19:04
php替换空格的方法:可以利用preg_replace()函数并结合正则表达式【\s+】来替换空格,如【preg_replace(\s+,,$contents)】。
php替换空格的方法:可以利用preg_replace()函数并结合正则表达式【/\s+/】来替换空格,如【preg_replace('/\s+/',' ',$contents)】。
(推荐教程:php视频教程)
举例:
替换所有空格为空
$cOntents=" abc ";
$cOntents=preg_replace('/\s+/','',$contents);
//结果$cOntents="abc";