php濾html的簡(jiǎn)單介紹
用string strip_tags string $str , string $allowable_tags str The input stringstring allowable_tags 允許的標(biāo)記 lt?php text = #39ltpTest paragraphltplt! Comment lta href=quot#fragmentquot。
lt?php$str = #39lta href=quot#quothreflta#39echo htmlspecialchars$strecho strip_tags$str。
花了點(diǎn)時(shí)間,試了N種終于搞定了有點(diǎn)難度!lt?php str = #39ltdivltspanlttablelttrlttd我ftyrtyrtltb是ltb中l(wèi)tstrong國(guó)ltstrong人ltimg src=imageslogojpglttdlttrlttableltspanltdiv#39preg。
php去除字符串中的html標(biāo)記,用到的工具notepad++,代碼如下1lt?phpecho strip_tagsquotHello lth1china!lth1quot?說(shuō)明strip_tags函數(shù)就是過(guò)濾html標(biāo)簽2輸出結(jié)果Hello china!注意事項(xiàng)win和linux都適用。
你這個(gè)問(wèn)題我之前做項(xiàng)目的時(shí)候也遇到過(guò),你可以從數(shù)據(jù)入庫(kù)時(shí)入手解決,具體做法就是你可在把數(shù)據(jù)存入到數(shù)據(jù)的時(shí)候用strip_tags函數(shù)剝離HTML標(biāo)簽,這樣你在查詢的時(shí)候就不會(huì)遇到這種情況了,完全都是數(shù)據(jù),如果存入數(shù)據(jù)庫(kù)的。
1,過(guò)濾所有html標(biāo)簽的正則表達(dá)式復(fù)制代碼 代碼如下lt?^+ 過(guò)濾所有html標(biāo)簽的屬性的正則表達(dá)式html = preg_replacequotltazAZ+^*quot,quotlt1quot,$html3,過(guò)濾部分html標(biāo)簽的正則表達(dá)式的。
掃描二維碼推送至手機(jī)訪問(wèn)。
版權(quán)聲明:本文由飛速云SEO網(wǎng)絡(luò)優(yōu)化推廣發(fā)布,如需轉(zhuǎn)載請(qǐng)注明出處。