How long is a piece of string?
That’s a question that’s been bugging me alot recently. Wondering if anyone’s got any idea’s how to solve this problem…
PHP’s serialize() function allows you represent PHP data structures as a string, which can then be parsed and restored to data with unserialize().
In general this approach works nicely – no need to reinvent stuff on PHP’s side at least. But there’s one problem; how long is a string? As this bug shows, it’s a problem.
var s = "Főő";
There’s a good explaination of the general problem from Derick here (PDF). You can see for yourself by running the following (make sure your editor is using something like a Unicode code page – see the global properties in SciTE);
The result will probably look something like;
Side note – although browsers automatically deal with form character encoding, it looks like XmlHttpRequest in both Mozilla and IE leaves it up to the developer to deal with, when POSTing data irrespective of the HTTP request headers you set (haven’t 100% confirmed that though).