I am using file_get_contents to populate a string with content. I am trying to safely pass it to JavaScript as a string without data corruption. I am currently using the rawurlencode and unescape combo. Unfortunately unicode characters are being lost along the way since some of the files contain unicode characters like ש which is “u05e9” in JavaScript. If file_get_contents reads such a unicode character I need it to convert to the second form before echoing it to JavaScript. Non-unicode characters can be represented by “x93” which is the same as “u0093” however saving two extra digits.
Any suggestions how to perform this string conversion with PHP? I’m thinking some kind of loop yet chr and ord are for ASCII and I’m trying to work with Unicode…