?
Solved

Convert NCR to javascript \u?

Posted on 2009-04-06
2
Medium Priority
?
2,295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Suggested Courses

770 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