字串中多個空格無法用自帶函式(trim)去除
阿新 • • 發佈:2021-01-25
在網上查了好多給出的方法,都沒解決
暫時定了個方法 批量處理
function trimSpace($text){ $t = str_split($text); $pre = ''; if(!empty($t)){ $i = 0; $new = []; foreach ($t as $v){ if($i!=0){ $pre = ord($t[$i-1]); } $current = ord($v); $i++; if($current==$pre && $current==32){ continue; } $new[] = $v; } $text = " ".join($new); } return $text; }