php - Convert non latin text to ASCII entries - without having to specify a locale -



php - Convert non latin text to ASCII entries - without having to specify a locale -

i working on project requires translation 40+ languages.

i have things sorted 1 buggging me. please take @ see need:

<script type="text/javascript"> /* purpose: converts non-latin based characters ascii entity value * usage: [string].encode() * arguments: none * returns: string */ string.prototype.encode = function() { homecoming this.replace(/([^\x01-\x7e])/g, function(s) { homecoming "&#"+s.charcodeat(0)+";"; }); }; /** * converts ascii entity value characters unicode equivelant * @return (string) */ string.prototype.decode = function() { number.prototype.tohex = function(pad) { var s = this.tostring(16).touppercase(); var v = ""; if(typeof pad == "number") { while(v.length + s.length < pad) { v += "0"; } } homecoming v + s; }; homecoming this.replace(/(&#([^;]*);)/g, function(s) { homecoming unescape("%u"+ number(regexp.$2).tohex(4)); }); }; function translate() { document.getelementbyid("txtoutput").value = document.getelementbyid("txtinput").value.encode(); } </script> <div class="admin_block"> <h1>translator</h1> <p>sometimes need add together non latin characters templates, php code , more. tool help convert text</p> <h2>type or paste non latin text in here</h2> <form name="input" onmousemove="translate();"> <textarea style="width: 900px" id="txtinput" onkeyup="translate();" onchange="translate();" onmouseup="translate();" onmousemove="translate();"></textarea> </form> <h2>copy , paste safe code below</h2> <form onmousemove="translate();"> <textarea style="width: 900px" id="txtoutput"></textarea><br /> <button id="btnselect" onclick="translate();document.getelementbyid('txtoutput').select(); homecoming false;">translate , select</button> </form> </div>

take russian text, thai etc , pop awesome js converter - outputs ascii values - these values can utilize in php array, html templates etc , fine.

i writing new method php translation class convert php language array new languages - heres issue. how can php js doing fine? have tried htmlentities,iconv etc. want see translated text such this:

&#1057;&#1086;&#1083;&#1086;&#1084;&#1086;&#1085;&#1086;&#1074;&#1099; &#1054;&#1089;&#1090;&#1088;&#1086;&#1074;&#1072;

Соломоновы Острова

well seems give me result after:

$s = htmlentities(mb_convert_encoding($s, 'html-entities', 'utf-8'));

i can see text result need re-create browser , paste new array.

php unicode utf-8 ascii non-latin

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -