Reputation: 220
I try to build Tagging System in vBulletin forum and it works fine.
But I have a problem with the quick edit of a post (using AJAX).
If I write the characters is in Hebrew language, it will replace the characters to Unicode.
An example of that when I write a post in the Hebrew language:
חחחחח לא?test!!
It will become to this:
%u05D7%u05D7%u05D7%u05D7%u05D7 %u05DC%u05D0?test!!
Upvotes: 0
Views: 103
Reputation: 3491
It looks as though the deprecated javascipt function escape()
is being used to encode the string. If you're echoing this out in the webpage via JavaScript, you could use unescape()
- see this fiddle. As mentioned above however, this is deprecated.
The functions that should instead be used are encodeURIComponent()
in place of escape()
, and decodeURIComponent()
in place of unescape()
. Then, you can use urldecode()
inside PHP to get the result you want, if this is a necessary step.
Given your current setup, to convert the unicode characters to html entities appropriate for rendering in a browser, the following should do what you want:
$str = preg_replace_callback('/%u([0-9a-fA-F]{4})/', function ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'HTML-ENTITIES', 'UCS-2BE');
}, $str);
Upvotes: 3