php怎么替换空格
来源:动视网
责编:小采
时间:2020-11-06 11:42:53
php怎么替换空格
php怎么替换空格:php替换空格的方法:可以利用preg_replace()函数并结合正则表达式【/\s+/】来替换空格,如【preg_replace('/\s+/',' ',$contents)】。函数介绍:preg_replace 函数执行一个正则表达式的搜索和替换。(推荐教程:php视频教程)举例:
导读php怎么替换空格:php替换空格的方法:可以利用preg_replace()函数并结合正则表达式【/\s+/】来替换空格,如【preg_replace('/\s+/',' ',$contents)】。函数介绍:preg_replace 函数执行一个正则表达式的搜索和替换。(推荐教程:php视频教程)举例:

函数介绍:
preg_replace 函数执行一个正则表达式的搜索和替换。
(推荐教程:php视频教程)
举例:
替换所有空格为空
$contents=" abc ";
$contents=preg_replace('/\s+/','',$contents);
//结果$contents="abc";
php怎么替换空格
php怎么替换空格:php替换空格的方法:可以利用preg_replace()函数并结合正则表达式【/\s+/】来替换空格,如【preg_replace('/\s+/',' ',$contents)】。函数介绍:preg_replace 函数执行一个正则表达式的搜索和替换。(推荐教程:php视频教程)举例: