php中的字符串常用函数 str_replace 字符串替换,替换全角空格
1 <?php 2 $str = "hello world!"; 3 echo(str_replace(array('hello', 'world'), array('tom', 'class'), $str); 4 //输出结果:tom class! 5 6 $str2 = "hello world!"; 7 echo(str_replace('hello', 'cat', $str2); 8 //输出结果:cat world!
第3行:数组依次对应替换
第7行:字符串部分替换
preg_replace('/[\s| ]+/', '', $a); // 去除全角空格。