-2

I have a .php file saved as UTF-8 and I would like to let it print out a character like €

How can I do it?

This is the source code of the example:

<?php
header('Content-Type: text/html; charset=UTF-8');

echo "€";
?>

The file was saved with notepad++ as UTF-8 but when I execute the file it just prints me out "?"


Answer

While the answer provided here UTF-8 all the way through fullfills various aspect of UTF-8, i found the answer to my question inside Matthew comment.

The .php file was saved as UTF-8 but WITH BOM. Within Notepad++ i choosed Format-> "UTF-8 without BOM" and the script worked.

Community
  • 1
  • 1
Scalax
  • 430
  • 1
  • 5
  • 12
  • This should work if the file is indeed encoded in UTF-8. Are you looking at this in a browser or on the command line? – deceze Nov 22 '13 at 17:44
  • 1
    Make sure that the file is saved as UTF8 wituout BOM : Copy the content of the file, open a new file encoded UTF8 w/o BOM, paste and save. – Matthew Nov 22 '13 at 17:48
  • While the answer provided here http://stackoverflow.com/questions/279170/utf-8-all-the-way-through fullfills various aspect of UTF-8, i found the answer to my question inside Matthew comment. The .php file was saved as UTF-8 but WITH BOM. With Notepad++ i choosed Format-> UTF-8 without BOM and the script worked. – Scalax Nov 25 '13 at 15:01

1 Answers1

1

It sounds like the Euro symbol in the file was actually entered as Windows-1252 or some other non-UTF-8 character set (encoding). How exactly did you type it in? Don't tell me that you copy and pasted it from a Word document!

For output to a browser, consider using &euro; instead -- guaranteed good. If it must be a hard coded binary multibyte character, you have to double check that you're actually editing in UTF-8 mode. I suspect that you aren't.

Phil Perry
  • 2,126
  • 14
  • 18