Itay Moav -Malimovka
Itay Moav -Malimovka

Reputation: 53606

How do I transform "é" to é in php?

I have an XML ISO-8859-1 page, in which I have to output symbols like é.
If I output é it errors out. é works just fine.
So, what PHP function should I use to transform é to é

I can't move to utf-8 (as I assume some will suggest and rightfully so) This is a huge, legacy code.

Upvotes: 3

Views: 1348

Answers (3)

Phliplip
Phliplip

Reputation: 3632

Try have a look in the comments 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 at lavin do me dot uk

Upvotes: 1

Artefacto
Artefacto

Reputation: 97845

Use mb_convert_encoding:

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

gives &#130;.

This example does not require that you enter the "é", which you may or may not be doing in ISO-8859-1:

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

Upvotes: 4

Dogbert
Dogbert

Reputation: 222428

var_dump(ord('é'));

Gives

int(233)

Perhaps, you could use

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

Upvotes: 2

Related Questions