I am trying to save foreign characters (e.g. أوه يمارس الجنس) through javascript to php and then stored in a mysql database.
I am able to do this but only if I do not escape() the string trying to be saved in javascript before sending to php.
Now for the problem.
Without an escaped string certain characters cannot be saved through my ajax type function due to the ampersand being seperators.
This is easily overcome by simply doing the escape() BUT the certain characters (e.g. أوه يمارس الجنس) will then not be ‘unescaped’ correctly in php.
How can I overcome this, or better yet ‘unescape’ it somehow properly in php?
I tried this on a string “(e.g. أوه يمارس الجنس) t”.
The data was decoded as “(e.g. %u0623%u0648%u0647 %u064A%u0645%u0627%u0631%u0633 %u0627%u0644%u062C%u0646%u0633) t”.
smftre: I faced a similar situation. In my case it was text in Thai language and after using urldecode, I never got back the original text… all of it was in the same %udddd format.
However, digging around a bit on the urldecode manual page I found a solution that has worked for me so far without a hitch.
I would have posted the exact link to the solution here… but the vBulletin’s refusing to let me add links.
You’ll have to use a custom function which will run a urldecode and a html_entity_decode consecutively to get back the original text…
I’m quoting the function here for you reference…
function utf8_urldecode($str) {
$str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\\\1;",urldecode($str));
return html_entity_decode($str,null,'UTF-8');;
}