替换第一个字符和第二个字符之间的空格,也反向删除最后一个字符和倒数第二个字符之间的空格


Replace spaces between first character and second one also reverse remove spaces between last and last but one?

如何替换或删除字符串的第一个和第二个字母之间的空格,并使用php删除最后一个和最后一个字符之间的空格?

的例子:

$string = "$ 1000,00 1000 10000 1000 $";

我想要像

那样显示字符串
$string ="$1000,00 1000 10000 1000$";

preg_replace ('/^(.) (.*) (.)$/', '$1$2$3', $string);

用无空格代替空格。

$string = str_replace(" ","",$string);

使用str_replace http://php.net/manual/en/function.str-replace.php

$string = str_replace(" ", "", $string); // $1000$