您好,欢迎访问一九零五行业门户网

php 删除字符串中的空格多种方法_PHP教程

本教程提供了几款php教程  删除字符串中的空格多种方法哦,用了php函数,str_replace,trim,正则等替换字符串的空格有效方法
用php自带的函数
str_replace(    , ,$str);
来替换
实例
看个高级一点的
php程序删除数组中字符串元素中的空格
$arr=array();
$arr[]=ad dfd  dfd;
$arr[]=saf sdf dsf;
$arr[]=sdf dsfgfd dd;
$arr[]=dfd dfferw ;
while(list($name,$value)=each($arr)){
echo $value;
$arr2[]=trim($value);//去空格
}
print_r($arr2);//这应该是你想要的数组吧~
?>用正则表达试删除空格
$string = preg_replace(/s+([rn$])/, 1, $string);when $ is inside [], www.45it.net does not represent the end of string
---------------------------------------------------------------
$string = preg_replace(/s+([x20]|$)/, 1, $string);
---------------------------------------------------------------
$string = preg_replace(/x20+([rn]|$)/, 1, $string);
---------------------------------------------------------------
$string = preg_replace('/([rn])[s]+/', '1', $string);
http://www.bkjia.com/phpjc/372043.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/372043.htmltecharticle本教程提供了几款php教程 删除字符串中的空格多种方法哦,用了php函数,str_replace,trim,正则等替换字符串的空格有效方法 用php自带的函数...
其它类似信息

推荐信息