删除 php 中单词之间的 space
Remove space in between words in php
如何删除 php 中两个单词之间的 space。例如 'Hello World'
应该 return 'HelloWorld'
。
我尝试使用 trim()
但它没有用。
您可以使用 str_replace
:
$str = str_replace(' ', '', $str);
你也可以这样做
$string = preg_replace('/\s+/', '', $string);
trim
用于删除字符串开头和结尾的空格。看here
preg_replace("/\s+/", "", $str);
完整代码:
$string="Hello World";
$string = str_replace(' ', '', $string);
试试这个:
function space_trim($st) {
return @str_replace(" ","",$st);
}
echo space_trim(" a fff jjj ");
如何删除 php 中两个单词之间的 space。例如 'Hello World'
应该 return 'HelloWorld'
。
我尝试使用 trim()
但它没有用。
您可以使用 str_replace
:
$str = str_replace(' ', '', $str);
你也可以这样做
$string = preg_replace('/\s+/', '', $string);
trim
用于删除字符串开头和结尾的空格。看here
preg_replace("/\s+/", "", $str);
完整代码:
$string="Hello World";
$string = str_replace(' ', '', $string);
试试这个:
function space_trim($st) {
return @str_replace(" ","",$st);
}
echo space_trim(" a fff jjj ");