茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1729061 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
PIMG_00434.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2011/11/2 16:00:13
[PHP]將html tags過濾掉的小方法

下面這個小function可以把html的tag過濾掉。
[code]
function striptext($document){
$search = array("' 'si", //style 先清掉
"' 'si", // strip out javascript
"'<[/!]*?[^<>]*?>'si", // strip out html tags
"'([rn])[s]+'", // strip out white space
"'&(quot|#34|#034|#x22);'i", // replace html entities
"'&(amp|#38|#038|#x26);'i", // added hexadecimal values
"'&(lt|#60|#060|#x3c);'i",
"'&(gt|#62|#062|#x3e);'i",
"'&(nbsp|#160|#xa0);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&(reg|#174);'i",
"'&(deg|#176);'i",
"'&(#39|#039|#x27);'",
"'&(euro|#8364);'i", // europe
);
$replace = array( "","",
"",
"1",
""",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
chr(174),
chr(176),
chr(39),
chr(128),

);

$text = preg_replace($search,$replace,$document);

return $text;
}
[code]

原文出處:[PHP]將html tags過濾掉的小方法 @ Bun's Java PHP XOOPS Note :: 隨意窩 Xuite日誌


冷日補充:

大家可能會問,PHP裡面不是已經有Function可以做這事情了嗎?

那位啥冷日還要轉這東西呢?

因為冷日覺得這個正規表示式寫法很可愛,可以運用在任何支援正規表示式的地方!

怎麼應用就看大家囉!

內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|