使用来自 table 的数据时,htmlentities() 不起作用
htmlentities() not working when using with data from a table
我正在尝试打印 table 中包含特殊字符(如 é)的数据。我使用了 htmlentities() 函数希望它能解决问题,但没有解决问题,数据根本不会出现。
例如:
我应该打印这个:
"Lightroom 3 pour les Phototographes du Numérique"
然而,字符 é 显示为 �。因此使用函数 htmlentities() 应该在逻辑上解决问题。然而,当它与包含字符 é 的字符串一起使用时,除了空的 space 之外什么也没有打印。在不包含特殊字符的字符串上使用该函数可以正常工作。
"Lightroom 3 pour les Phototographes du Numerique"
按原样打印,而
"Lightroom 3 pour les Phototographes du Numérique"
打印为
" "
我的数据库和所有 table 都是 UTF-8 编码的,还有我的 html 文档。
当您阅读 htmlentities 文档时,它说
If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.
按照文档中的建议,您可以尝试强制编码(可能 "ISO-8859-1" 或 "ISO-8859-15")?
我正在尝试打印 table 中包含特殊字符(如 é)的数据。我使用了 htmlentities() 函数希望它能解决问题,但没有解决问题,数据根本不会出现。
例如:
我应该打印这个:
"Lightroom 3 pour les Phototographes du Numérique"
然而,字符 é 显示为 �。因此使用函数 htmlentities() 应该在逻辑上解决问题。然而,当它与包含字符 é 的字符串一起使用时,除了空的 space 之外什么也没有打印。在不包含特殊字符的字符串上使用该函数可以正常工作。
"Lightroom 3 pour les Phototographes du Numerique"
按原样打印,而
"Lightroom 3 pour les Phototographes du Numérique"
打印为
" "
我的数据库和所有 table 都是 UTF-8 编码的,还有我的 html 文档。
当您阅读 htmlentities 文档时,它说
If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.
按照文档中的建议,您可以尝试强制编码(可能 "ISO-8859-1" 或 "ISO-8859-15")?