[英]Remove space in between words in php
How do I remove space between two words in php. 如何删除php中两个单词之间的空格。 For example
'Hello World'
should return 'HelloWorld'
. 例如,
'Hello World'
应返回'HelloWorld'
。 I tried using trim()
but it did not work. 我尝试使用
trim()
但是没有用。
您可以使用str_replace
:
$str = str_replace(' ', '', $str);
您也可以这样做
$string = preg_replace('/\s+/', '', $string);
Complete code: 完整的代码:
$string="Hello World";
$string = str_replace(' ', '', $string);
Try this: 尝试这个:
function space_trim($st) {
return @str_replace(" ","",$st);
}
echo space_trim(" a fff jjj ");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.