Php 将非拉丁文字转换为ASCII条目-无需指定区域设置

Php 将非拉丁文字转换为ASCII条目-无需指定区域设置,php,unicode,utf-8,ascii,non-latin,Php,Unicode,Utf 8,Ascii,Non Latin,我正在做一个需要翻译成40多种语言的项目 我把大部分事情都整理好了,但这件事真的让我烦透了。请看一下这个,看看我需要什么: <script type="text/javascript"> /* Purpose: Converts all non-latin based characters to their ASCII entity value * Usage: [String].encode() * Arguments: none * Returns: String */

我正在做一个需要翻译成40多种语言的项目

我把大部分事情都整理好了,但这件事真的让我烦透了。请看一下这个,看看我需要什么:

<script type="text/javascript">
/* Purpose: Converts all non-latin based characters to their ASCII entity value
 * Usage: [String].encode()
 * Arguments: none
 * Returns: String
 */
String.prototype.encode = function() {
        return this.replace(/([^\x01-\x7E])/g, function(s) { return         "&#"+s.charCodeAt(0)+";"; });
};

/**
 * Converts all ASCII entity value characters into their 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";
                    }
            }
            return v + s;
    };
    return this.replace(/(&#([^;]*);)/g, function(s) { return 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 you need to add non latin Characters to the templates, php code and more. This tool will help you convert your 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 and paste this safe code below</h2>
<form onmousemove="translate();">
    <textarea style="width: 900px" id="txtOutput"></textarea><br />
    <button id="btnSelect" onclick="translate();document.getElementById('txtOutput').select(); return false;">Translate and select</button>
</form>

</div>

这似乎给了我我想要的结果:

$s = htmlentities(mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'));

我现在可以看到需要从浏览器复制并粘贴到新数组中的文本结果。

俄语、泰语等不能有ASCII值……为什么不使用UTF-8?所有网站都应该在UTF-8。我使用UTF8,但对于我的PHP文件,我不能使用它。看看我的JS转换器,看看我需要什么。你说的是HTML实体,而不是ASCII。为什么HTML实体是必需的呢?charCodeAt不返回ASCII值,而是返回unicode。。
$s = htmlentities(mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'));