Rumah > Soal Jawab > teks badan
天蓬老师2017-04-11 09:45:03
自己写个替换
$str = 'zxcvgsdg gfsgfs sdfsfg';
echo test($str);
function test($str)
{
$search = array(" "," ");
$replace = array("","");
return str_replace($search, $replace, $str);
}
大家讲道理2017-04-11 09:45:03
方式A:
$string = ' 测试 ';
$string = trim(trim($string," "));
方式B:
$string = ' 测试 ';
$string = trim(str_replace(' ', ' ', $string));
黄舟2017-04-11 09:45:03
我说这样实现的
/**
* [filterBlank 去掉字符串两边空格]
* @author Shaowei Pu <542684913@qq.cn>
* @CreateTime 2017-02-06T17:31:29+0800
* @param [type] $str [传入字符串]
* @return [type] [返回trim后的]
*/
function filterBlank( $str )
{
mb_regex_encoding('utf-8');
$str = mb_ereg_replace(' ', '', $str);
return trim($str);
}
$str = 'jkgsdgsgsdgs gsdg gsd';
echo filterBlank($str);