PHP 中的 str_replace() 函数可以实现
str_replace() 函数使用一个字符串替换字符串中的另一些字符。
str_replace(find,replace,string,count)
参数说明
find 必需。规定要查找的值。
replace 必需。规定替换 find 中的值的值。
string 必需。规定被搜索的字符串。
count 可选。一个变量,对替换数进行计数。
注释:该函数对大小写敏感。请使用 str_ireplace() 执行对大小写不敏感的搜索。
例如:
echo str_replace(" ","","Hello world!");
?>
输出:
Helloworld!
同理,preg_replace() 函数也可以实现 (执行一个正则表达式的搜索和替换)
例如:
echo preg_replace("/\s/","","Hello world!");
?>
输出:
Helloworld!
$a = "你 好";
$b = str_replace(" ","",$a);
echo $a;
echo "