去掉字符中的中文空格
\u00A0:不间断空格,主要用在office中,让一个单词在结尾处不会换行显示
\u0020:半角空格(英文符号),代码中常用的
\u3000:全角空格(中文符号),中文文章中使用
我们经常会发现在数据库中存在一种空白字符不是空格也不是制表符,无法替换,此时可能是由于在excel或者office中复制过来的特殊字符导致的

function replaceSpace($str) { // $str = str_replace(" ", " ", $str); $str = trim($str); //头尾的空格去掉 $json_encode_str = json_encode($str); if (strpos($json_encode_str, '\u00a0') || strpos($json_encode_str, '\u0020') || strpos($json_encode_str, '\u3000')) { $json_encode_str = str_replace("\u00a0", " ", $json_encode_str); $json_encode_str = str_replace("\u0020", " ", $json_encode_str); $json_encode_str = str_replace("\u3000", " ", $json_encode_str); return json_decode($json_encode_str); } return $str; }
本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/articles/18456260
浙公网安备 33010602011771号