htmlspecialchars_decode就可以实现了啊

解决方案 »

  1.   

    PHP >5.1有htmlspecialchars_decode()
    否则试试get_html_translation_table()吧
      

  2.   

    奇怪~  get_html_translation_table 不支持汉字吗?<?php
    $trans = get_html_translation_table(HTML_ENTITIES);
    $str = "测试";
    $encoded = strtr($str, $trans);
    echo $encoded;
    ?>怎么会产生乱码?
      

  3.   

    function formatcontent($text){
    $trans = get_html_translation_table(HTML_SPECIALCHARS);
    $trans = array_flip($trans);
    $text = strtr($text, $trans);
    //$text = str_replace("\n", "<br>", $text);
    //$text = str_replace(" ", "&nbsp;", $text);
    return $text;
    }
    这样子行不?
      

  4.   

    <?php
    $trans = get_html_translation_table(HTML_ENTITIES);
    $str = "测试";
    $encoded = strtr($str, $trans);
    echo $encoded;
    ?>怎么会产生乱码?
      

  5.   

    当然是乱码!
    你的代码执行的结果是
    &sup2;&acirc;&Ecirc;&Ocirc;这就是说,你把"测试"的内码按字节当作扩展ascii码处理了这与你的本意是不符合的
    我觉得你需要的是这个
    <?php
    $trans = get_html_translation_table(HTML_ENTITIES);
    $str = "&sup2;&acirc;&Ecirc;&Ocirc;";
    $encoded = strtr($str, array_flip($trans));
    echo $encoded; //out 测试
    ?>