//php 有三種方法來解決 //1、使用str_replace 來替換換行 $str = str_replace(array("\r\n", "\r", "\n"), "", $str); //2、使用正則替換 $str = preg_replace('//s*/', '', $str); //3、使用php定義好的變量 (建議使用) $str = str_replace(PHP_EOL, '', $str);
// 轉為前台可顯示的換行, nl2br 的方向函數參考php手冊 $str = "a b e f c"; echo nl2br($str);