我有一根像“汤姆·曾傑瑞”这样的弦。我想从字符串的末尾去掉多余的空格。也就是说,期望的输出是“汤姆·曾傑瑞”。我该怎么做?
发布于 2017-08-16 18:01:59
在php中有一个trim方法:http://php.net/manual/en/function.trim.php
trim("Tom Jerry ");发布于 2017-08-16 18:03:47
使用trim(字符串)函数??
发布于 2017-08-16 18:04:06
您应该改用rtrim。它将删除字符串末尾的多余空格,并且比使用preg_replace更快。
$str = "This is a string. ";
echo rtrim($str);来源:Remove extra space at the end of string using preg_replace
https://stackoverflow.com/questions/45710523
复制相似问题