views:

595

answers:

3

I am really trying to show what htmlentities gives me, but it doesn't give & euro; for the € character.

I am trying

echo htmlentities(htmlentities("LISBOA-VIENA DESDE 99€ TAXAS INCLUÍDAS, RESERVE JÁ",ENT_COMPAT,ISO-8859-1),ENT_COMPAT,ISO-8859-1);
    echo '<br>';
    echo htmlentities(htmlentities("LISBOA-VIENA DESDE 99€ TAXAS INCLUÍDAS, RESERVE JÁ",ENT_COMPAT,UTF-8),ENT_COMPAT,UTF-8);

and for both I get

LISBOA-VIENA DESDE 99€ TAXAS INCLU& Iacute;DAS, RESERVE J& Aacute;

LISBOA-VIENA DESDE 99€ TAXAS INCLU& Iacute;DAS, RESERVE J& Aacute;

I never get a & euro;

Anyone know how to get this right?

+3  A: 

Use ISO-8859-15 instead of ISO-8859-1.

ISO-8859-15 (ISO Latin 9) differs from ISO-8859-1 (ISO Latin 1) and adds the Euro sign and French and Finnish letters missing in Latin-1 (ISO-8859-1).

echo htmlentities('Working htmlentities() now 99€ off!', ENT_COMPAT, 'ISO-8859-15');

should return

Working htmlentities() now 99&euro; off!
Aron Rotteveel
I tried this and it just returned a normal € :(
AntonioCS
+1  A: 

This is discussed here; it seems € (&#8364;) works often.

hstoerr
+2  A: 

What is the original file encoding of the file in which you use these statements?

If you're on Windows chances are high that the file is encoded with Windows-1252 (CP1252) and not in ISO-8859-1, ISO-8859-2 or UTF-8.

The sign is 0x80 in Windows-1252, ISO-8859-15 encodes the sign with 0xA4 while ISO-8859-1 doesn't have a sign altogether (see answer from Aron Rotteveel). You must ensure that you pass the correct charset used for the string into htmlentities(). Best practice would be to use UTF-8 encoding for all of your files.

If htmlentities("LISBOA-VIENA DESDE 99€ TAXAS INCLUÍDAS, RESERVE JÁ",ENT_COMPAT,'Windows-1252') works then you're using the CP1252 charset.

I also just noticed that you're missing quotes around the charsets in your example above. This could also be the cause of trouble.

Stefan Gehrig