【问题标题】:Php - How do perform string conversion from HTML special char to UTF-8Php - 如何执行从 HTML 特殊字符到 UTF-8 的字符串转换
【发布时间】:2013-08-02 16:12:01
【问题描述】:

我需要将 HTML 特殊字符(如“ ”)转换为 UTF-8 中的对应字符,如字符串中的“”(空格)。

有这样的功能吗?

【问题讨论】:

  • 我只是想知道,这是因为您已经在页面中有 ,还是您希望对数据文件中包含的内容执行“查找和替换”?不得不问,以防万一那是你真正想要的。
  • 我从我的数据库中的一个表中得到一个字段,该字段包含可能遭受转义的 HTML 内容。我需要将此字符串提供给模板,并且需要转换 HTML 特殊字符。 html_entity_decode() 返回类似“无效多字节...”的错误
  • @AngeloG。如果您想查找和替换/删除,那么您可以使用这个 sn-p:$text_description=" "; $text_description = str_replace(' ', ' ', $text_description); echo $text_description; 您可以将 (' ', ' ', $text_description) 替换为 (' ', '', $text_description),并完全删除  

标签: php string escaping special-characters


【解决方案1】:

你可以使用这个功能:

html_entity_decode()

html_entity_decode — 将所有 HTML 实体转换为其适用的字符 (包括 UTF-8)

http://php.net/manual/en/function.html-entity-decode.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 2013-01-24
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    相关资源
    最近更新 更多