【问题标题】:How to convert special characters to html words through PHP?如何通过PHP将特殊字符转换为html单词?
【发布时间】:2014-03-25 07:27:09
【问题描述】:

当我通过php在xml文件中显示时,我在mysql数据中有很多这样的特殊字符。

—,”,’,“...etc

我想用php转换成原词。

【问题讨论】:

    标签: php html decode


    【解决方案1】:

    您正在寻找html_entity_decode

    【讨论】:

    • 使用该标签后,我得到了 xml 错误。这是第 5 行第 859 列的错误:xmlParseEntityRef: no name
    【解决方案2】:
    $s = ' —,”,’,“';
    echo html_entity_decode($s);
    

    您只需要http://www.php.net/manual/en/function.html-entity-decode.php

    【讨论】:

    • 使用该标签后,我得到了 xml 错误。这是第 5 行第 859 列的错误:xmlParseEntityRef: no name
    【解决方案3】:

    您应该选择htmlspecialchars_decode,因为html_entity_decode 是一个较轻的版本

    <?php
    $s = '&mdash;,&rdquo;,&rsquo;,&ldquo;';
    echo htmlspecialchars_decode($s);
    

    OUTPUT :

    —,”,’,“
    

    【讨论】:

      【解决方案4】:
      <?php
      $orig = "I'll \"walk\" the <b>dog</b> now";
      

      $a = htmlentities($orig);

        echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
      

      $b = html_entity_decode($a);

        echo $b; // I'll "walk" the <b>dog</b> now
      ?>
      

      【讨论】:

      • 使用该标签后,我得到了 xml 错误。这是第 5 行第 859 列的错误:xmlParseEntityRef: no name
      猜你喜欢
      • 2017-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多