除了smarty中的html标签之外,如何逃避htmlentities

时间:2014-05-04 18:36:19

标签: smarty

示例:

$smarty->assign('string', '<p>Germans use "Ümlauts" and pay in €uro</p>');

{$string|escape|unescape:"html"}

结果:

<p>Germans use 'Ümlauts' and pay in €uro</p>

我做错了什么......

2 个答案:

答案 0 :(得分:1)

出现这种情况的原因不止一个。

检查

的编码
  1. 你的php文件,
  2. 您的模板文件和
  3. 您的html输出(doctype和meta标签),
  4. 通常它是引发这种情况的其中之一。

    为了避免这种问题,在许多情况下最好的方法是在整个项目中使用utf8,这意味着将smarty模板和php转换为utf8并在html标头中使用正确的utf8标签。

    HTML 4.01:

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    

    HTML5:

    <meta charset="UTF-8">
    

答案 1 :(得分:1)

您还应该在文档中添加UTF-8以转义函数:http://www.smarty.net/docsv2/en/language.modifier.escape

相关问题