Section Menu:  

转义html标签符函数:html_escape()

  • 发布时间: 2019-08-28 00:00
  •    阅读: 3082   

描述

html_escape() 转义html标签符,类似PHP的htmlspecialchars函数,将<>&"'转义成&amp;&lt,&gt
html_escape() 接收两个参数,第一个参数为要转义的字符、列表、字典,第二个参数为是否要转义单/双引号


 
语法

以下是 html_escape() 的语法:

html_escape(exam, quote=True)

参数

    ● exam [str|list|dict]:要转义的字符、列表、字典。
    ● quote [bool]:是否转义单/双引号。


返回值

返回一个字符串、列表、字典类型的数据


实例

以下展示了使用 html_escape() 的实例:

from kyger.utility import html_escape
print(html_escape('Test'))
print(html_escape(['Test', 'OK']))
print(html_escape({'a': 'Test', 'b': 'OK'})

以上实例运行后输出的结果为:

<a href="test">Test</a>
['<a href="test">Test</a>', '<b>OK</b>']
{'a': '<a>Test</a>', 'b': '<b>OK</b>'}

适应版本

v1.0.1