14

I expected this code:

define('EURO_SIMBOLO', chr(128));
$euro = EURO_SIMBOLO;
var_dump($euro);

to show the symbol, but it doesn't. Why does this happen?

Paolo Stefan
  • 10,112
  • 5
  • 45
  • 64
tirenweb
  • 30,963
  • 73
  • 183
  • 303
  • 3
    This depends on the character set you are using. What encoding are your pages in? – Pekka Feb 03 '11 at 12:31
  • Hi, Pekka, how to know the encoding of my pages? – tirenweb Feb 03 '11 at 12:34
  • @user the browser's "encoding" or "character set" menu will have a check mark on the encoding it is currently using. – Pekka Feb 03 '11 at 12:35
  • The Euro symbol does not exist in **Latin-1**. It has an representation in ISO-8859-15 (Latin-9) however, and the charcode would be `\xA4` or `164` then. – mario Feb 03 '11 at 12:41

5 Answers5

16

If you want to go with Unicode, UTF-8 more specifically, which I prefer because of its flexibility, you can output the Euro sign using:

echo "\xE2\x82\xAc"; // 3 bytes-long multibyte character
netcoder
  • 66,435
  • 19
  • 125
  • 142
3

Instead of € (alt + 0128)

switch your euro code to

€
Lucas Zamboulis
  • 2,494
  • 5
  • 24
  • 27
2

This will only work if you're using a 125x code page. The fact is that the euro character is not included in all extended ASCII character sets (introduced in ISO/IEC 8859-15), however it does have a de-facto Unicode character.

If this is simply for displaying in a browser, consider using either '€' or '€'

Leigh
  • 12,859
  • 3
  • 39
  • 60
1

If you are using such a character set with the euro-symbol you’re most likely using iso-8859-15 in which the '€' character is defined at position 164. So you might have more luck if you replace 128 by 164, although this won’t help you in utf-8 environments in which the previous answer might be more suited.

rumpel
  • 7,870
  • 2
  • 38
  • 39
0

In the CP1252 encoding of € has the code 128; In ISO-8859-15 the code is 164; Macintosh Roman is 219;

The euro sign is a part of the ASCII. Look that http://www.ascii-code.com/