我想去掉字符串中多余的空格。我已经尝试过 trim
、ltrim
、rtrim
等方法,但它们都不起作用,我甚至尝试了以下方法。
//This removes all the spaces even the space between the words
// which i want to be kept
$new_string = preg_replace('/\s/u', '', $old_string);
有没有解决方法?
更新:
输入字符串:
"
Hello Welcome
to India "
输出字符串:
"Hello Welcome to India"
^\s*|\s*$
。 - Faiz Shukri" a b "
变成"a b"
还是"a b"
? - Tim Pietzcker