Home > php教程 > PHP源码 > body text

php 取除连续空格与换行代码

WBOY
Release: 2016-06-08 17:28:54
Original
1020 people have browsed it

php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数

第一种:
$content=str_replace("n","",$content);
echo $content;


第二种:
$content=preg_replace("/s/","",$content);
echo $content;


$str="i   am    a     booknnnnnmoth";
//去除所有的空格和换行符
echo preg_replace("/[s]{2,}/","",$str).'
';
//去除多余的空格和换行符,只保留一个
echo preg_replace("/([s]{2,})/","\1",$str);
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!