2

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 ...

Michel Keijzers
  • 15,025
  • 28
  • 93
  • 119
Salman
  • 145
  • 2
  • 2
  • 9
  • Is your source file encoding properly set to UTF8? You should check it in your text editor. – Guillaume Poussel Mar 07 '12 at 13:43
  • How do you open the file? Perhaps it is saved right, but shown wrong in your viewer (vim etc.). On what kind of system are your files located? Unix, Windwos – DKSan Mar 07 '12 at 13:44
  • Its located on Windows...When i open the file with wordpad the text is converted there as well ... – Salman Mar 07 '12 at 13:46

1 Answers1

3

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

Community
  • 1
  • 1
James Andres
  • 1,522
  • 14
  • 20
  • When i save the file as txt it works fine but having problems with .eps file ... Working on Windows – Salman Mar 07 '12 at 13:49
  • 1
    The file extension you choose should not affect things. More likely, some part of your toolchain is creating a non-UTF8 file. You can use a program like [`file`](http://gnuwin32.sourceforge.net/packages/file.htm) to check if your files are UTF-8. Fwiw I tried this on OS X and it worked fine. Running `file` on my local `test.eps` returns `test.eps: UTF-8 Unicode text, with no line terminators`. – James Andres Mar 07 '12 at 14:13
  • 1
    The other possibility, I forgot to mention, is that the program you are opening the `test.eps` file with are interpreting the file as though it were non-UTF8. Also (I'm not sure if this is the issue), don't use notepad.exe or wordpad.exe I wouldn't trust those to handle fine grained issues with character encoding. – James Andres Mar 07 '12 at 14:19
  • Yeah you are right... wordpad was making a mess of it.On Notepad++ it is fine.But the issue is still there, the default program for test.eps is Adobe illustratoe CS3, when i open it in that it shows `ˆ“` – Salman Mar 07 '12 at 14:41
  • That I can't help you with much unfortunately. Perhaps your output does not conform to the EPS standards? Perhaps try some basic sample EPS files and work from there? This might help http://en.wikipedia.org/wiki/Encapsulated_PostScript – James Andres Mar 08 '12 at 00:03