2009年11月12日 星期四

[PHP] 去除斷行、空白字元方法

移除斷行字元 :
//利用正規表示式將內容的斷行(\r\n)字元去除
preg_replace( "/\s/", "" , $content );

移除空白字元 :
// 移除前後空白字
$str = trim($str);
// 移除重覆的空白
$str = preg_replace('/\s(?=\s)/', '', $str);
// 移除非空白的間距變成一般的空白
$str = preg_replace('/[\n\r\t]/', ' ', $str);


原文出處:
http://uiop7890.pixnet.net/blog/post/22872252

沒有留言: