www.webdeveloper.com
Results 1 to 2 of 2

Thread: Converting utf8 text to html text javascript

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    1

    Converting utf8 text to html text javascript

    So I started writing some functions to do this but i cannot be the first one to think of this or what to accomplish this...in javascript.

    So for utf8 to html I'm doing something like this

    Code:
    function utf8tohtml(utftxt)
    {
            utftxt = utftxt.replace(/&/g,"&")
            utftxt = utftxt.replace(//g,"Á")
            utftxt = utftxt.replace(//g,"É")
            utftxt = utftxt.replace(//g,"Í")
            utftxt = utftxt.replace(//g,"Ó")
            utftxt = utftxt.replace(//g,"Ú")
            utftxt = utftxt.replace(//g,"Ý")
            utftxt = utftxt.replace(//g,"ý")
            utftxt = utftxt.replace(//g,"á")
            utftxt = utftxt.replace(//g,"é")
            return utftxt
    }
    for html to utf8 i'm doing something like this

    Code:
    function htmltoutf(txt)
    {
            txt = txt.replace(/}/,'}');      // right curly brace
            txt = txt.replace(/~/,'~');      // tilde
            txt = txt.replace(//,'');      // box
            txt = txt.replace(/€/,'');      // Euro
            txt = txt.replace(//,'');      // florin
            txt = txt.replace(//,'');      // ellipsis
            txt = txt.replace(//,'');      // circumflex accent
            txt = txt.replace(//,'');      // 
            txt = txt.replace(//,'');      // capital OE ligature
            return txt
    }
    and there is more...i've just stopped here for this example...

    appreciate the ideas...

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Code:
    function escapeExtended(s){
     return s.replace(/([\x80-\xff])/g, function (a, b) {
       var c = b.charCodeAt();
       return "&#" + b.charCodeAt()+";" 
     });
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles