str_replace(array("\r", "\n", "\r\n", "\n\r"), '', $str); $str就是你的原來字串,利用str_replace將所有可能的換行符號網且放到陣列裡,只要符合其中一組,就會換成'',這樣就清掉了.