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

字符串里貌似空格,如何删除?

$str ='                            controllable eu valence for photoluminescence tuning in apatite-typed';在编码为gbk的情况下是'聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽controllable eu valence for photoluminescence tuning in apatite-typed';在utf-8下是'                            controllable eu valence for photoluminescence tuning in apatite-typed';

如何去除空格?

回复内容: $str ='                            controllable eu valence for photoluminescence tuning in apatite-typed';在编码为gbk的情况下是'聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽controllable eu valence for photoluminescence tuning in apatite-typed';在utf-8下是'                            controllable eu valence for photoluminescence tuning in apatite-typed';

如何去除空格?

用 $str = preg_replace('/^[\pz\pc]+|[\pz\pc]+$/u','',$str);
http://php.net/manual/zh/regexp.reference.unicode.php
在选用 utf-8模式时用于匹配通用字符类型
pc:所有的unicode“other”
pz:所有的unicode“separator” ,所有空格和不可见字符
php合并多个连续的空格:
$output = preg_replace('/\s+/', ' ', $input);
\s 匹配任何空白字符,包括空格、制表符、换页符等等,等价于[ \f\n\r\t\v]。
http://php.net/manual/zh/reference.pcre.pattern.syntax.php
$str = $str.replace(/s/g,'');
urlencode一下看看是什么字符,(是空格还是其他的)
其它类似信息

推荐信息