Solved

Convert NCR to javascript \u?

Posted on 2009-04-06
2
2,233 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:scottg
  • 2
2 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24084601
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

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 24084628
Clearer to see


 <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(''); 

 }

 var str = "&#49548;&#44060;"

 document.write(str.replace(/&/g,'&amp;')+':['+str+']:['+ncr2utf(str)+']') //  should become \uC18C\uAC1C.

 </script>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now