I saved file named "File1.txt" with the content (English and Hebrew) "שלום hello". its encode is Unicode. when I do "readfile" and send a header:
Content-type: text/plain;charset=utf-8
the Hebrew chars disappear. The weird part is that when I open the file again I see the Hebrew chars(Unicode supports Hebrew), and UTF-8 extends Unicode so theoretically I don't need to do any conversion. What should I do?
The line "its encod[ing] is Unicode" makes no sense. There are many ways Unicode can be represented in a text file (UTF-8 is one of them).
If you mean - it was saved in Notepad as Unicode, that means the file is in UTF-16LE. Send the respective header:
And it'll work.
To answer the question in the title, normally the
iconv()
function is used in PHP to convert between encodings. A word of caution though - it might not be available on the Web server in a hosted environment.