php - Convert unicode to characters -
i try build tagging system in vbulletin forum , works fine.
but have 1 problem in quick edit of post (using ajax).
if write characters in hebrew, replace characters in unicode.
example write in post:
חחחחח לא?test!!
this makes this:
%u05d7%u05d7%u05d7%u05d7%u05d7 %u05dc%u05d0?test!!
it looks though deprecated javascipt function escape()
being used encode string. if you're echoing out in webpage via javascript, use unescape()
- see this fiddle. mentioned above however, deprecated.
the functions should instead used encodeuricomponent()
in place of escape()
, , decodeuricomponent()
in place of unescape()
. then, can use urldecode()
inside php result want, if necessary step.
given current setup, convert unicode characters html entities appropriate rendering in browser, following should 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);
Comments
Post a Comment