在PHP中,可以使用htmlentities()函數(shù)來轉(zhuǎn)義html,把字符轉(zhuǎn)換為HTML實(shí)體;也可以使用html_entity_decode()函數(shù)來反轉(zhuǎn)義html,把HTML實(shí)體轉(zhuǎn)換為字符。
本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版,DELL G3電腦
php中轉(zhuǎn)義html標(biāo)簽
1、htmlentities()函數(shù)轉(zhuǎn)義html
htmlentities() 函數(shù)把字符轉(zhuǎn)換為 HTML 實(shí)體。
提示:要把 HTML 實(shí)體轉(zhuǎn)換回字符,請(qǐng)使用 html_entity_decode() 函數(shù)。
提示:請(qǐng)使用 get_html_translation_table() 函數(shù)來返回 htmlentities() 使用的翻譯表。
語法
htmlentities(string,flags,character-set,double_encode)
【推薦學(xué)習(xí):《PHP視頻教程》】
2、html_entity_decode()函數(shù)反轉(zhuǎn)義html
html_entity_decode() 函數(shù)把 HTML 實(shí)體轉(zhuǎn)換為字符。
html_entity_decode() 函數(shù)是 htmlentities() 函數(shù)的反函數(shù)。
語法
html_entity_decode(string,flags,character-set)