代码之家  ›  专栏  ›  技术社区  ›  Itay Moav -Malimovka

“我该如何转变”é” 至é在php中?

  •  3
  • Itay Moav -Malimovka  · 技术社区  · 15 年前


    如果我输出 é 它出错了。 é 很好用。
    那么,我应该用什么PHP函数来转换呢 é é

    3 回复  |  直到 15 年前
        1
  •  1
  •   Phliplip    15 年前

    试着看看这里的评论; http://php.net/manual/en/function.htmlentities.php

    phil at lavin dot me dot uk
    08-Apr-2010 03:34 
    
    The following will make a string completely safe for XML:
    
    <?php
    function philsXMLClean($strin) {
        $strout = null;
    
        for ($i = 0; $i < strlen($strin); $i++) {
                $ord = ord($strin[$i]);
    
                if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
                        $strout .= "&amp;#{$ord};";
                }
                else {
                        switch ($strin[$i]) {
                                case '<':
                                        $strout .= '&lt;';
                                        break;
                                case '>':
                                        $strout .= '&gt;';
                                        break;
                                case '&':
                                        $strout .= '&amp;';
                                        break;
                                case '"':
                                        $strout .= '&quot;';
                                        break;
                                default:
                                        $strout .= $strin[$i];
                        }
                }
        }
    
        return $strout;
    }
    ?> 
    

    所有的功劳都归菲尔在拉文做我点英国

        2
  •  4
  •   Artefacto    15 年前

    使用 mb_convert_encoding :

    mb_convert_encoding("é", "HTML-ENTITIES", "ISO-8859-1");
    

    &#130; .

    此示例不要求您输入“”,您可以在ISO-8859-1中输入“”,也可以不输入“”:

    mb_convert_encoding(chr(130), "HTML-ENTITIES", "ISO-8859-1");
    
        3
  •  2
  •   Dogbert    15 年前

    var_dump(ord('é'));

    给予

    int(233)

    print '&#' . ord('é') . ';';