Link to home
Start Free TrialLog in
Avatar of scottg
scottg

asked on

Convert NCR to javascript \u?

Hi, I'm trying to convert text in "numerical character reference" format to javascript escape (\u) format.  for example 소개 should become \uC18C\uAC1C.

I need to do this conversion in a Javascript routine or PHP.

Any ideas?  I'm lost
kenw232@yahoo.com
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

If it is a string:



 <script>
 function d2h(d) {return d.toString(16).toUpperCase();}
 function ncr2utf(str) {
   var chars = str.replace(/\&\#/g,'').split(';')
   for (var i=0;i<chars.length;i++) if (chars[i]) chars[i]="\\u"+d2h(parseInt(chars[i]));
   return chars.join(''); 
 }
 document.write(ncr2utf("&#49548;&#44060;")) //  should become \uC18C\uAC1C.
 </script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial