How to convert "é" to é in php?

I have an ISO-8859-1 XML page in which I should output characters such as é.
If I post é, it will fail. éworks great.
So which PHP function should I use to convert étoé

I can not go to utf-8 (as I believe, some of them will be offered by right). This is a huge, outdated code.

+3
source share
3 answers

Try looking here. 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;
}
?> 

All credits go to phil in lavin do me dot uk

+1
source

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");
+4

var_dump(ord('é'));

int(233)

,

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

Source: https://habr.com/ru/post/1747884/


All Articles