Write Special characters in a file

2019-07-17 11:08发布

问题:

I am trying to write data in a .eps file, Here is my code

header('Content-Type: text/html; charset=utf-8');'

$var = 'ê';

echo $var;

$file = 'test.eps';

file_put_contents($file, $var);

But when i open test.eps, the data written is ê it should have been ê

Please Help ...

回答1:

I believe you are dealing with either:

  1. The character encoding of the source code file you have created (make sure it is UTF-8!)
  2. The default encoding for file_put_contents is utf8, so you should be okay there but your OS or distro might be interfering. What OS / distro / version are you using?

Edit From the comments it sounds like an issue with your text editor. Try creating a new copy of the file using a proper programming text editor. https://stackoverflow.com/questions/173112/best-lightweight-ide-text-editor