【问题标题】:How not to not to convert certain symbols with htmlentities()?如何不使用 htmlentities() 转换某些符号?
【发布时间】:2012-02-13 10:13:26
【问题描述】:

我如何“要求”htmlentities() 不要转换某些符号?例如,

php,

<?php echo htmlentities(file_get_contents('fonts.css'),ENT_QUOTES);?>

字体.css,

@font-face {
    font-family: 'ChunkFiveRoman';
    src: url('chunkfive-webfont.eot'); /* EOT file for IE */
    src: local('☺'), url('chunkfive-webfont.ttf') format('truetype'); /* TTF file for CSS3 browsers */
}

结果,

@font-face {
    font-family: 'ChunkFiveRoman';
    src: url('chunkfive-webfont.eot'); /* EOT file for IE */
    src: local('�'), url('chunkfive-webfont.ttf') format('truetype'); /* TTF file for CSS3 browsers */
}

我想保持 '☺' 原样,但不想将其转换为 'âº'。

有可能吗?

【问题讨论】:

  • htmlentities 不能这样工作,所以问题出在其他地方。也许您的 css 文件是用 utf-8 编码的,但您将其显示为单字节编码的 HTML?
  • 谢谢乔恩。可能我正在以单字节编码将 css 显示为 HTML ......但现在它似乎与 mario 的答案一起工作正常。

标签: php special-characters html-entities


【解决方案1】:

使用htmlentities的第三个参数。它指定字符集:

<?php echo htmlentities(file_get_contents('fonts.css'),ENT_QUOTES,"UTF-8");?>

这避免了将笑脸转换为拉丁 1 字节等效项。 (这就是它的样子。)

【讨论】:

    猜你喜欢
    • 2012-07-01
    • 2015-01-25
    • 2017-05-23
    • 2016-04-29
    • 2019-03-04
    • 1970-01-01
    • 2015-03-22
    • 1970-01-01
    • 2011-07-28
    相关资源
    最近更新 更多