html_escape() 轉(zhuǎn)義html標(biāo)簽符,類似PHP的htmlspecialchars函數(shù),將<>&"'轉(zhuǎn)義成&;<,>
html_escape() 接收兩個參數(shù),第一個參數(shù)為要轉(zhuǎn)義的字符、列表、字典,第二個參數(shù)為是否要轉(zhuǎn)義單/雙引號
以下是 html_escape() 的語法:
html_escape(exam, quote=True)
● exam [str|list|dict]:要轉(zhuǎn)義的字符、列表、字典。
● quote [bool]:是否轉(zhuǎn)義單/雙引號。
返回一個字符串、列表、字典類型的數(shù)據(jù)
以下展示了使用 html_escape() 的實(shí)例:
from kyger.utility import html_escape print(html_escape('Test')) print(html_escape(['Test', 'OK'])) print(html_escape({'a': 'Test', 'b': 'OK'})
以上實(shí)例運(yùn)行后輸出的結(jié)果為:
<a href="test">Test</a> ['<a href="test">Test</a>', '<b>OK</b>'] {'a': '<a>Test</a>', 'b': '<b>OK</b>'}