将外来字符更改为对应的罗马字符

发布于 2024-11-26 23:55:21 字数 144 浏览 1 评论 0原文

我正在使用 php,我想知道是否有一种预定义的方法可以将外来字符转换为非外来字符。

ê、ë、é 等字符均生成 'e'
我正在寻找一个函数,它将接受一个字符串并返回它,不带特殊字符。
任何想法将不胜感激!

I am using php and I was wondering if there was a predefined way to convert foreign characters to their non-foreign alternatives.

Characters such as ê, ë, é all resulting to 'e'.
I'm looking for a function that would take a string and return it without the special characters.
Any ideas would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

待天淡蓝洁白时 2024-12-03 23:55:21

在找不到合适的转换器之后,我创建了自己的集合来满足我的需求,包括我最喜欢的西里尔转换,默认情况下有许多变体。

function transliterateString($txt) {
    $transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a', 'Ă' => 'A', 'â' => 'a', 'Â' => 'A', 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', 'ħ' => 'h', 'Ħ' => 'H', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'î' => 'i', 'Î' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'į' => 'i', 'Į' => 'I', 'ī' => 'i', 'Ī' => 'I', 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'Ĺ' => 'L', 'ľ' => 'l', 'Ľ' => 'L', 'ļ' => 'l', 'Ļ' => 'L', 'ł' => 'l', 'Ł' => 'L', 'ṁ' => 'm', 'Ṁ' => 'M', 'ń' => 'n', 'Ń' => 'N', 'ň' => 'n', 'Ň' => 'N', 'ñ' => 'n', 'Ñ' => 'N', 'ņ' => 'n', 'Ņ' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ô' => 'o', 'Ô' => 'O', 'ő' => 'o', 'Ő' => 'O', 'õ' => 'o', 'Õ' => 'O', 'ø' => 'oe', 'Ø' => 'OE', 'ō' => 'o', 'Ō' => 'O', 'ơ' => 'o', 'Ơ' => 'O', 'ö' => 'oe', 'Ö' => 'OE', 'ṗ' => 'p', 'Ṗ' => 'P', 'ŕ' => 'r', 'Ŕ' => 'R', 'ř' => 'r', 'Ř' => 'R', 'ŗ' => 'r', 'Ŗ' => 'R', 'ś' => 's', 'Ś' => 'S', 'ŝ' => 's', 'Ŝ' => 'S', 'š' => 's', 'Š' => 'S', 'ṡ' => 's', 'Ṡ' => 'S', 'ş' => 's', 'Ş' => 'S', 'ș' => 's', 'Ș' => 'S', 'ß' => 'SS', 'ť' => 't', 'Ť' => 'T', 'ṫ' => 't', 'Ṫ' => 'T', 'ţ' => 't', 'Ţ' => 'T', 'ț' => 't', 'Ț' => 'T', 'ŧ' => 't', 'Ŧ' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ŭ' => 'u', 'Ŭ' => 'U', 'û' => 'u', 'Û' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ű' => 'u', 'Ű' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ų' => 'u', 'Ų' => 'U', 'ū' => 'u', 'Ū' => 'U', 'ư' => 'u', 'Ư' => 'U', 'ü' => 'ue', 'Ü' => 'UE', 'ẃ' => 'w', 'Ẃ' => 'W', 'ẁ' => 'w', 'Ẁ' => 'W', 'ŵ' => 'w', 'Ŵ' => 'W', 'ẅ' => 'w', 'Ẅ' => 'W', 'ý' => 'y', 'Ý' => 'Y', 'ỳ' => 'y', 'Ỳ' => 'Y', 'ŷ' => 'y', 'Ŷ' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ź' => 'z', 'Ź' => 'Z', 'ž' => 'z', 'Ž' => 'Z', 'ż' => 'z', 'Ż' => 'Z', 'þ' => 'th', 'Þ' => 'Th', 'µ' => 'u', 'а' => 'a', 'А' => 'a', 'б' => 'b', 'Б' => 'b', 'в' => 'v', 'В' => 'v', 'г' => 'g', 'Г' => 'g', 'д' => 'd', 'Д' => 'd', 'е' => 'e', 'Е' => 'E', 'ё' => 'e', 'Ё' => 'E', 'ж' => 'zh', 'Ж' => 'zh', 'з' => 'z', 'З' => 'z', 'и' => 'i', 'И' => 'i', 'й' => 'j', 'Й' => 'j', 'к' => 'k', 'К' => 'k', 'л' => 'l', 'Л' => 'l', 'м' => 'm', 'М' => 'm', 'н' => 'n', 'Н' => 'n', 'о' => 'o', 'О' => 'o', 'п' => 'p', 'П' => 'p', 'р' => 'r', 'Р' => 'r', 'с' => 's', 'С' => 's', 'т' => 't', 'Т' => 't', 'у' => 'u', 'У' => 'u', 'ф' => 'f', 'Ф' => 'f', 'х' => 'h', 'Х' => 'h', 'ц' => 'c', 'Ц' => 'c', 'ч' => 'ch', 'Ч' => 'ch', 'ш' => 'sh', 'Ш' => 'sh', 'щ' => 'sch', 'Щ' => 'sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'y', 'ь' => '', 'Ь' => '', 'э' => 'e', 'Э' => 'e', 'ю' => 'ju', 'Ю' => 'ju', 'я' => 'ja', 'Я' => 'ja');
    return str_replace(array_keys($transliterationTable), array_values($transliterationTable), $txt);
}

After failing to find suitable convertors I created my own collection that suits my needs including my favorite Cyrillic conversion that by default has numerous variations.

function transliterateString($txt) {
    $transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a', 'Ă' => 'A', 'â' => 'a', 'Â' => 'A', 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', 'ħ' => 'h', 'Ħ' => 'H', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'î' => 'i', 'Î' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'į' => 'i', 'Į' => 'I', 'ī' => 'i', 'Ī' => 'I', 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'Ĺ' => 'L', 'ľ' => 'l', 'Ľ' => 'L', 'ļ' => 'l', 'Ļ' => 'L', 'ł' => 'l', 'Ł' => 'L', 'ṁ' => 'm', 'Ṁ' => 'M', 'ń' => 'n', 'Ń' => 'N', 'ň' => 'n', 'Ň' => 'N', 'ñ' => 'n', 'Ñ' => 'N', 'ņ' => 'n', 'Ņ' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ô' => 'o', 'Ô' => 'O', 'ő' => 'o', 'Ő' => 'O', 'õ' => 'o', 'Õ' => 'O', 'ø' => 'oe', 'Ø' => 'OE', 'ō' => 'o', 'Ō' => 'O', 'ơ' => 'o', 'Ơ' => 'O', 'ö' => 'oe', 'Ö' => 'OE', 'ṗ' => 'p', 'Ṗ' => 'P', 'ŕ' => 'r', 'Ŕ' => 'R', 'ř' => 'r', 'Ř' => 'R', 'ŗ' => 'r', 'Ŗ' => 'R', 'ś' => 's', 'Ś' => 'S', 'ŝ' => 's', 'Ŝ' => 'S', 'š' => 's', 'Š' => 'S', 'ṡ' => 's', 'Ṡ' => 'S', 'ş' => 's', 'Ş' => 'S', 'ș' => 's', 'Ș' => 'S', 'ß' => 'SS', 'ť' => 't', 'Ť' => 'T', 'ṫ' => 't', 'Ṫ' => 'T', 'ţ' => 't', 'Ţ' => 'T', 'ț' => 't', 'Ț' => 'T', 'ŧ' => 't', 'Ŧ' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ŭ' => 'u', 'Ŭ' => 'U', 'û' => 'u', 'Û' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ű' => 'u', 'Ű' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ų' => 'u', 'Ų' => 'U', 'ū' => 'u', 'Ū' => 'U', 'ư' => 'u', 'Ư' => 'U', 'ü' => 'ue', 'Ü' => 'UE', 'ẃ' => 'w', 'Ẃ' => 'W', 'ẁ' => 'w', 'Ẁ' => 'W', 'ŵ' => 'w', 'Ŵ' => 'W', 'ẅ' => 'w', 'Ẅ' => 'W', 'ý' => 'y', 'Ý' => 'Y', 'ỳ' => 'y', 'Ỳ' => 'Y', 'ŷ' => 'y', 'Ŷ' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ź' => 'z', 'Ź' => 'Z', 'ž' => 'z', 'Ž' => 'Z', 'ż' => 'z', 'Ż' => 'Z', 'þ' => 'th', 'Þ' => 'Th', 'µ' => 'u', 'а' => 'a', 'А' => 'a', 'б' => 'b', 'Б' => 'b', 'в' => 'v', 'В' => 'v', 'г' => 'g', 'Г' => 'g', 'д' => 'd', 'Д' => 'd', 'е' => 'e', 'Е' => 'E', 'ё' => 'e', 'Ё' => 'E', 'ж' => 'zh', 'Ж' => 'zh', 'з' => 'z', 'З' => 'z', 'и' => 'i', 'И' => 'i', 'й' => 'j', 'Й' => 'j', 'к' => 'k', 'К' => 'k', 'л' => 'l', 'Л' => 'l', 'м' => 'm', 'М' => 'm', 'н' => 'n', 'Н' => 'n', 'о' => 'o', 'О' => 'o', 'п' => 'p', 'П' => 'p', 'р' => 'r', 'Р' => 'r', 'с' => 's', 'С' => 's', 'т' => 't', 'Т' => 't', 'у' => 'u', 'У' => 'u', 'ф' => 'f', 'Ф' => 'f', 'х' => 'h', 'Х' => 'h', 'ц' => 'c', 'Ц' => 'c', 'ч' => 'ch', 'Ч' => 'ch', 'ш' => 'sh', 'Ш' => 'sh', 'щ' => 'sch', 'Щ' => 'sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'y', 'ь' => '', 'Ь' => '', 'э' => 'e', 'Э' => 'e', 'ю' => 'ju', 'Ю' => 'ju', 'я' => 'ja', 'Я' => 'ja');
    return str_replace(array_keys($transliterationTable), array_values($transliterationTable), $txt);
}
一身仙ぐ女味 2024-12-03 23:55:21

我的第一个推荐是 iconv 函数。即因为它内置于 PHP 中,所以不需要任何外部或第三方库。此外,它的功能旨在精确执行您想要完成的任务(接受字符集作为输入,并输出备用字符集,特别是从 UTF-8 到 ASCII)。以下是如何调用此函数的示例:

$clean_ascii_output = iconv('UTF-8', 'ASCII//TRANSLIT', $utf8_input);

有关此 PHP 函数的详细信息,请参见此处: http://php.net/manual/en/function.iconv.php

注意: iconv 函数接受字符串输入,因此您需要迭代数据并解析它,以便您可以正在传递一个字符串输入。

My first recommendation is the iconv function. Namely because it's built into PHP, so doesn't require any external or 3rd party libraries. In addition, it's a function that's designed to do precisely what you are trying to accomplish (accept on character set as input, and output an alternate character set, specifically going from UTF-8 to ASCII). Below is an example of how to call this function:

$clean_ascii_output = iconv('UTF-8', 'ASCII//TRANSLIT', $utf8_input);

More information about the specifics of this PHP function can be found here: http://php.net/manual/en/function.iconv.php

Note: The iconv function accepts string inputs, so you'll want to iterate over data, and parse it such that you are passing in a string input.

中性美 2024-12-03 23:55:21

我编写了这个函数,它使用 PHP 中内置的 HTML 实体转换表来罗马化字符:

function Unaccent($string)
{
    if (strpos($string = htmlentities($string, ENT_QUOTES, 'UTF-8'), '&') !== false)
    {
        $string = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8');
    }

    return $string;
}

它的工作原理是应用 htmlentities(),然后删除常见的实体后缀,一个简单的方法例如:

 - ã = ã -> a
 - Ã = Ã -> A
 - õ = õ -> o
 - Õ = Õ -> O
 - æ = æ  -> ae
 - Æ = Æ  -> AE

请注意,要使其正常工作,您的文件需要使用 UTF-8 进行编码(显然没有 BOM)。

另请参阅我的其他答案了解另一个示例。

I coded this function which uses the HTML entities translation table built-in into PHP to romanize chars:

function Unaccent($string)
{
    if (strpos($string = htmlentities($string, ENT_QUOTES, 'UTF-8'), '&') !== false)
    {
        $string = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8');
    }

    return $string;
}

It works by applying htmlentities() and then removing common entities suffixes, a simple example:

 - ã = ã -> a
 - Ã = Ã -> A
 - õ = õ -> o
 - Õ = Õ -> O
 - æ = æ  -> ae
 - Æ = Æ  -> AE

Beware that for this to work properly your files need to be encoded in UTF-8 (no BOM obviously).

See also my other answer for another example.

请止步禁区 2024-12-03 23:55:21

看到这个老问题,仍然不知道最好的答案是什么。
如果它可以帮助其他人,这是我从

自动组成的数组http://www.fileformat.info/info/charset/UTF-8/list.htm

array ("À" => "A",
"Á" => "A",
"Â" => "A",
"Ã" => "A",
"Ä" => "A",
"Å" => "A",
"Æ" => "AE",
"Ç" => "C",
"È" => "E",
"É" => "E",
"Ê" => "E",
"Ë" => "E",
"Ì" => "I",
"Í" => "I",
"Î" => "I",
"Ï" => "I",
"Ð" => "ETH",
"Ñ" => "N",
"Ò" => "O",
"Ó" => "O",
"Ô" => "O",
"Õ" => "O",
"Ö" => "O",
"Ø" => "O",
"Ù" => "U",
"Ú" => "U",
"Û" => "U",
"Ü" => "U",
"Ý" => "Y",
"Þ" => "THORN",
"ß" => "s",
"à" => "a",
"á" => "a",
"â" => "a",
"ã" => "a",
"ä" => "a",
"å" => "a",
"æ" => "ae",
"ç" => "c",
"è" => "e",
"é" => "e",
"ê" => "e",
"ë" => "e",
"ì" => "i",
"í" => "i",
"î" => "i",
"ï" => "i",
"ð" => "eth",
"ñ" => "n",
"ò" => "o",
"ó" => "o",
"ô" => "o",
"õ" => "o",
"ö" => "o",
"ø" => "o",
"ù" => "u",
"ú" => "u",
"û" => "u",
"ü" => "u",
"ý" => "y",
"þ" => "thorn",
"ÿ" => "y",
"Ā" => "A",
"ā" => "a",
"Ă" => "A",
"ă" => "a",
"Ą" => "A",
"ą" => "a",
"Ć" => "C",
"ć" => "c",
"Ĉ" => "C",
"ĉ" => "c",
"Ċ" => "C",
"ċ" => "c",
"Č" => "C",
"č" => "c",
"Ď" => "D",
"ď" => "d",
"Đ" => "D",
"đ" => "d",
"Ē" => "E",
"ē" => "e",
"Ĕ" => "E",
"ĕ" => "e",
"Ė" => "E",
"ė" => "e",
"Ę" => "E",
"ę" => "e",
"Ě" => "E",
"ě" => "e",
"Ĝ" => "G",
"ĝ" => "g",
"Ğ" => "G",
"ğ" => "g",
"Ġ" => "G",
"ġ" => "g",
"Ģ" => "G",
"ģ" => "g",
"Ĥ" => "H",
"ĥ" => "h",
"Ħ" => "H",
"ħ" => "h",
"Ĩ" => "I",
"ĩ" => "i",
"Ī" => "I",
"ī" => "i",
"Ĭ" => "I",
"ĭ" => "i",
"Į" => "I",
"į" => "i",
"İ" => "I",
"ı" => "i",
"Ĵ" => "J",
"ĵ" => "j",
"Ķ" => "K",
"ķ" => "k",
"ĸ" => "kra",
"Ĺ" => "L",
"ĺ" => "l",
"Ļ" => "L",
"ļ" => "l",
"Ľ" => "L",
"ľ" => "l",
"Ŀ" => "L",
"ŀ" => "l",
"Ł" => "L",
"ł" => "l",
"Ń" => "N",
"ń" => "n",
"Ņ" => "N",
"ņ" => "n",
"Ň" => "N",
"ň" => "n",
"ʼn" => "n",
"Ŋ" => "ENG",
"ŋ" => "eng",
"Ō" => "O",
"ō" => "o",
"Ŏ" => "O",
"ŏ" => "o",
"Ő" => "O",
"ő" => "o",
"Ŕ" => "R",
"ŕ" => "r",
"Ŗ" => "R",
"ŗ" => "r",
"Ř" => "R",
"ř" => "r",
"Ś" => "S",
"ś" => "s",
"Ŝ" => "S",
"ŝ" => "s",
"Ş" => "S",
"ş" => "s",
"Š" => "S",
"š" => "s",
"Ţ" => "T",
"ţ" => "t",
"Ť" => "T",
"ť" => "t",
"Ŧ" => "T",
"ŧ" => "t",
"Ũ" => "U",
"ũ" => "u",
"Ū" => "U",
"ū" => "u",
"Ŭ" => "U",
"ŭ" => "u",
"Ů" => "U",
"ů" => "u",
"Ű" => "U",
"ű" => "u",
"Ų" => "U",
"ų" => "u",
"Ŵ" => "W",
"ŵ" => "w",
"Ŷ" => "Y",
"ŷ" => "y",
"Ÿ" => "Y",
"Ź" => "Z",
"ź" => "z",
"Ż" => "Z",
"ż" => "z",
"Ž" => "Z",
"ž" => "z",
"ſ" => "s",
"ƀ" => "b",
"Ɓ" => "B",
"Ƃ" => "B",
"ƃ" => "b",
"Ƅ" => "SIX",
"ƅ" => "six",
"Ɔ" => "O",
"Ƈ" => "C",
"ƈ" => "c",
"Ɖ" => "D",
"Ɗ" => "D",
"Ƌ" => "D",
"ƌ" => "d",
"ƍ" => "delta",
"Ǝ" => "E",
"Ə" => "SCHWA",
"Ɛ" => "E",
"Ƒ" => "F",
"ƒ" => "f",
"Ɠ" => "G",
"Ɣ" => "GAMMA",
"ƕ" => "hv",
"Ɩ" => "IOTA",
"Ɨ" => "I",
"Ƙ" => "K",
"ƙ" => "k",
"ƚ" => "l",
"ƛ" => "lambda",
"Ɯ" => "M",
"Ɲ" => "N",
"ƞ" => "n",
"Ɵ" => "O",
"Ơ" => "O",
"ơ" => "o",
"Ƣ" => "OI",
"ƣ" => "oi",
"Ƥ" => "P",
"ƥ" => "p",
"Ƨ" => "TWO",
"ƨ" => "two",
"Ʃ" => "ESH",
"ƫ" => "t",
"Ƭ" => "T",
"ƭ" => "t",
"Ʈ" => "T",
"Ư" => "U",
"ư" => "u",
"Ʊ" => "UPSILON",
"Ʋ" => "V",
"Ƴ" => "Y",
"ƴ" => "y",
"Ƶ" => "Z",
"ƶ" => "z",
"Ʒ" => "EZH",
"Ƹ" => "EZH",
"ƹ" => "ezh",
"ƺ" => "ezh",
"Ƽ" => "FIVE",
"ƽ" => "five",
"DŽ" => "DZ",
"Dž" => "D",
"dž" => "dz",
"LJ" => "LJ",
"Lj" => "L",
"lj" => "lj",
"NJ" => "NJ",
"Nj" => "N",
"nj" => "nj",
"Ǎ" => "A",
"ǎ" => "a",
"Ǐ" => "I",
"ǐ" => "i",
"Ǒ" => "O",
"ǒ" => "o",
"Ǔ" => "U",
"ǔ" => "u",
"Ǖ" => "U",
"ǖ" => "u",
"Ǘ" => "U",
"ǘ" => "u",
"Ǚ" => "U",
"ǚ" => "u",
"Ǜ" => "U",
"ǜ" => "u",
"ǝ" => "e",
"Ǟ" => "A",
"ǟ" => "a",
"Ǡ" => "A",
"ǡ" => "a",
"Ǣ" => "AE",
"ǣ" => "ae",
"Ǥ" => "G",
"ǥ" => "g",
"Ǧ" => "G",
"ǧ" => "g",
"Ǩ" => "K",
"ǩ" => "k",
"Ǫ" => "O",
"ǫ" => "o",
"Ǭ" => "O",
"ǭ" => "o",
"Ǯ" => "EZH",
"ǯ" => "ezh",
"ǰ" => "j",
"DZ" => "DZ",
"Dz" => "D",
"dz" => "dz",
"Ǵ" => "G",
"ǵ" => "g",
"Ƕ" => "HWAIR",
"Ƿ" => "WYNN",
"Ǹ" => "N",
"ǹ" => "n",
"Ǻ" => "A",
"ǻ" => "a",
"Ǽ" => "AE",
"ǽ" => "ae",
"Ǿ" => "O",
"ǿ" => "o",
"Ȁ" => "A",
"ȁ" => "a",
"Ȃ" => "A",
"ȃ" => "a",
"Ȅ" => "E",
"ȅ" => "e",
"Ȇ" => "E",
"ȇ" => "e",
"Ȉ" => "I",
"ȉ" => "i",
"Ȋ" => "I",
"ȋ" => "i",
"Ȍ" => "O",
"ȍ" => "o",
"Ȏ" => "O",
"ȏ" => "o",
"Ȑ" => "R",
"ȑ" => "r",
"Ȓ" => "R",
"ȓ" => "r",
"Ȕ" => "U",
"ȕ" => "u",
"Ȗ" => "U",
"ȗ" => "u",
"Ș" => "S",
"ș" => "s",
"Ț" => "T",
"ț" => "t",
"Ȝ" => "YOGH",
"ȝ" => "yogh",
"Ȟ" => "H",
"ȟ" => "h",
"Ƞ" => "N",
"ȡ" => "d",
"Ȣ" => "OU",
"ȣ" => "ou",
"Ȥ" => "Z",
"ȥ" => "z",
"Ȧ" => "A",
"ȧ" => "a",
"Ȩ" => "E",
"ȩ" => "e",
"Ȫ" => "O",
"ȫ" => "o",
"Ȭ" => "O",
"ȭ" => "o",
"Ȯ" => "O",
"ȯ" => "o",
"Ȱ" => "O",
"ȱ" => "o",
"Ȳ" => "Y",
"ȳ" => "y",
"ȴ" => "l",
"ȵ" => "n",
"ȶ" => "t",
"ȷ" => "j",
"ȸ" => "db",
"ȹ" => "qp",
"Ⱥ" => "A",
"Ȼ" => "C",
"ȼ" => "c",
"Ƚ" => "L",
"Ⱦ" => "T",
"ȿ" => "s",
"ɀ" => "z",
"Ɂ" => "STOP",
"ɂ" => "stop",
"Ƀ" => "B",
"Ʉ" => "U",
"Ʌ" => "V",
"Ɇ" => "E",
"ɇ" => "e",
"Ɉ" => "J",
"ɉ" => "j",
"Ɋ" => "Q",
"ɋ" => "q",
"Ɍ" => "R",
"ɍ" => "r",
"Ɏ" => "Y",
"ɏ" => "y",
"ɐ" => "a",
"ɑ" => "alpha",
"ɒ" => "alpha",
"ɓ" => "b",
"ɔ" => "o",
"ɕ" => "c",
"ɖ" => "d",
"ɗ" => "d",
"ɘ" => "e",
"ə" => "schwa",
"ɚ" => "schwa",
"ɛ" => "e",
"ɜ" => "e",
"ɝ" => "e",
"ɞ" => "e",
"ɟ" => "j",
"ɠ" => "g",
"ɡ" => "script",
"ɣ" => "gamma",
"ɤ" => "rams",
"ɥ" => "h",
"ɦ" => "h",
"ɧ" => "heng",
"ɨ" => "i",
"ɩ" => "iota",
"ɫ" => "l",
"ɬ" => "l",
"ɭ" => "l",
"ɮ" => "lezh",
"ɯ" => "m",
"ɰ" => "m",
"ɱ" => "m",
"ɲ" => "n",
"ɳ" => "n",
"ɵ" => "barred",
"ɷ" => "omega",
"ɸ" => "phi",
"ɹ" => "r",
"ɺ" => "r",
"ɻ" => "r",
"ɼ" => "r",
"ɽ" => "r",
"ɾ" => "r",
"ɿ" => "r",
"ʂ" => "s",
"ʃ" => "esh",
"ʄ" => "j",
"ʅ" => "squat",
"ʆ" => "esh",
"ʇ" => "t",
"ʈ" => "t",
"ʉ" => "u",
"ʊ" => "upsilon",
"ʋ" => "v",
"ʌ" => "v",
"ʍ" => "w",
"ʎ" => "y",
"ʐ" => "z",
"ʑ" => "z",
"ʒ" => "ezh",
"ʓ" => "ezh",
"ʚ" => "e",
"ʞ" => "k",
"ʠ" => "q",
"ʣ" => "dz",
"ʤ" => "dezh",
"ʥ" => "dz",
"ʦ" => "ts",
"ʧ" => "tesh",
"ʨ" => "tc",
"ʩ" => "feng",
"ʪ" => "ls",
"ʫ" => "lz",
"ʮ" => "h",
"ʯ" => "h")

Saw this old question and still don't know what the best answer is.
In case it can help others, here is a array I made up automatically from

http://www.fileformat.info/info/charset/UTF-8/list.htm

array ("À" => "A",
"Á" => "A",
"Â" => "A",
"Ã" => "A",
"Ä" => "A",
"Å" => "A",
"Æ" => "AE",
"Ç" => "C",
"È" => "E",
"É" => "E",
"Ê" => "E",
"Ë" => "E",
"Ì" => "I",
"Í" => "I",
"Î" => "I",
"Ï" => "I",
"Ð" => "ETH",
"Ñ" => "N",
"Ò" => "O",
"Ó" => "O",
"Ô" => "O",
"Õ" => "O",
"Ö" => "O",
"Ø" => "O",
"Ù" => "U",
"Ú" => "U",
"Û" => "U",
"Ü" => "U",
"Ý" => "Y",
"Þ" => "THORN",
"ß" => "s",
"à" => "a",
"á" => "a",
"â" => "a",
"ã" => "a",
"ä" => "a",
"å" => "a",
"æ" => "ae",
"ç" => "c",
"è" => "e",
"é" => "e",
"ê" => "e",
"ë" => "e",
"ì" => "i",
"í" => "i",
"î" => "i",
"ï" => "i",
"ð" => "eth",
"ñ" => "n",
"ò" => "o",
"ó" => "o",
"ô" => "o",
"õ" => "o",
"ö" => "o",
"ø" => "o",
"ù" => "u",
"ú" => "u",
"û" => "u",
"ü" => "u",
"ý" => "y",
"þ" => "thorn",
"ÿ" => "y",
"Ā" => "A",
"ā" => "a",
"Ă" => "A",
"ă" => "a",
"Ą" => "A",
"ą" => "a",
"Ć" => "C",
"ć" => "c",
"Ĉ" => "C",
"ĉ" => "c",
"Ċ" => "C",
"ċ" => "c",
"Č" => "C",
"č" => "c",
"Ď" => "D",
"ď" => "d",
"Đ" => "D",
"đ" => "d",
"Ē" => "E",
"ē" => "e",
"Ĕ" => "E",
"ĕ" => "e",
"Ė" => "E",
"ė" => "e",
"Ę" => "E",
"ę" => "e",
"Ě" => "E",
"ě" => "e",
"Ĝ" => "G",
"ĝ" => "g",
"Ğ" => "G",
"ğ" => "g",
"Ġ" => "G",
"ġ" => "g",
"Ģ" => "G",
"ģ" => "g",
"Ĥ" => "H",
"ĥ" => "h",
"Ħ" => "H",
"ħ" => "h",
"Ĩ" => "I",
"ĩ" => "i",
"Ī" => "I",
"ī" => "i",
"Ĭ" => "I",
"ĭ" => "i",
"Į" => "I",
"į" => "i",
"İ" => "I",
"ı" => "i",
"Ĵ" => "J",
"ĵ" => "j",
"Ķ" => "K",
"ķ" => "k",
"ĸ" => "kra",
"Ĺ" => "L",
"ĺ" => "l",
"Ļ" => "L",
"ļ" => "l",
"Ľ" => "L",
"ľ" => "l",
"Ŀ" => "L",
"ŀ" => "l",
"Ł" => "L",
"ł" => "l",
"Ń" => "N",
"ń" => "n",
"Ņ" => "N",
"ņ" => "n",
"Ň" => "N",
"ň" => "n",
"ʼn" => "n",
"Ŋ" => "ENG",
"ŋ" => "eng",
"Ō" => "O",
"ō" => "o",
"Ŏ" => "O",
"ŏ" => "o",
"Ő" => "O",
"ő" => "o",
"Ŕ" => "R",
"ŕ" => "r",
"Ŗ" => "R",
"ŗ" => "r",
"Ř" => "R",
"ř" => "r",
"Ś" => "S",
"ś" => "s",
"Ŝ" => "S",
"ŝ" => "s",
"Ş" => "S",
"ş" => "s",
"Š" => "S",
"š" => "s",
"Ţ" => "T",
"ţ" => "t",
"Ť" => "T",
"ť" => "t",
"Ŧ" => "T",
"ŧ" => "t",
"Ũ" => "U",
"ũ" => "u",
"Ū" => "U",
"ū" => "u",
"Ŭ" => "U",
"ŭ" => "u",
"Ů" => "U",
"ů" => "u",
"Ű" => "U",
"ű" => "u",
"Ų" => "U",
"ų" => "u",
"Ŵ" => "W",
"ŵ" => "w",
"Ŷ" => "Y",
"ŷ" => "y",
"Ÿ" => "Y",
"Ź" => "Z",
"ź" => "z",
"Ż" => "Z",
"ż" => "z",
"Ž" => "Z",
"ž" => "z",
"ſ" => "s",
"ƀ" => "b",
"Ɓ" => "B",
"Ƃ" => "B",
"ƃ" => "b",
"Ƅ" => "SIX",
"ƅ" => "six",
"Ɔ" => "O",
"Ƈ" => "C",
"ƈ" => "c",
"Ɖ" => "D",
"Ɗ" => "D",
"Ƌ" => "D",
"ƌ" => "d",
"ƍ" => "delta",
"Ǝ" => "E",
"Ə" => "SCHWA",
"Ɛ" => "E",
"Ƒ" => "F",
"ƒ" => "f",
"Ɠ" => "G",
"Ɣ" => "GAMMA",
"ƕ" => "hv",
"Ɩ" => "IOTA",
"Ɨ" => "I",
"Ƙ" => "K",
"ƙ" => "k",
"ƚ" => "l",
"ƛ" => "lambda",
"Ɯ" => "M",
"Ɲ" => "N",
"ƞ" => "n",
"Ɵ" => "O",
"Ơ" => "O",
"ơ" => "o",
"Ƣ" => "OI",
"ƣ" => "oi",
"Ƥ" => "P",
"ƥ" => "p",
"Ƨ" => "TWO",
"ƨ" => "two",
"Ʃ" => "ESH",
"ƫ" => "t",
"Ƭ" => "T",
"ƭ" => "t",
"Ʈ" => "T",
"Ư" => "U",
"ư" => "u",
"Ʊ" => "UPSILON",
"Ʋ" => "V",
"Ƴ" => "Y",
"ƴ" => "y",
"Ƶ" => "Z",
"ƶ" => "z",
"Ʒ" => "EZH",
"Ƹ" => "EZH",
"ƹ" => "ezh",
"ƺ" => "ezh",
"Ƽ" => "FIVE",
"ƽ" => "five",
"DŽ" => "DZ",
"Dž" => "D",
"dž" => "dz",
"LJ" => "LJ",
"Lj" => "L",
"lj" => "lj",
"NJ" => "NJ",
"Nj" => "N",
"nj" => "nj",
"Ǎ" => "A",
"ǎ" => "a",
"Ǐ" => "I",
"ǐ" => "i",
"Ǒ" => "O",
"ǒ" => "o",
"Ǔ" => "U",
"ǔ" => "u",
"Ǖ" => "U",
"ǖ" => "u",
"Ǘ" => "U",
"ǘ" => "u",
"Ǚ" => "U",
"ǚ" => "u",
"Ǜ" => "U",
"ǜ" => "u",
"ǝ" => "e",
"Ǟ" => "A",
"ǟ" => "a",
"Ǡ" => "A",
"ǡ" => "a",
"Ǣ" => "AE",
"ǣ" => "ae",
"Ǥ" => "G",
"ǥ" => "g",
"Ǧ" => "G",
"ǧ" => "g",
"Ǩ" => "K",
"ǩ" => "k",
"Ǫ" => "O",
"ǫ" => "o",
"Ǭ" => "O",
"ǭ" => "o",
"Ǯ" => "EZH",
"ǯ" => "ezh",
"ǰ" => "j",
"DZ" => "DZ",
"Dz" => "D",
"dz" => "dz",
"Ǵ" => "G",
"ǵ" => "g",
"Ƕ" => "HWAIR",
"Ƿ" => "WYNN",
"Ǹ" => "N",
"ǹ" => "n",
"Ǻ" => "A",
"ǻ" => "a",
"Ǽ" => "AE",
"ǽ" => "ae",
"Ǿ" => "O",
"ǿ" => "o",
"Ȁ" => "A",
"ȁ" => "a",
"Ȃ" => "A",
"ȃ" => "a",
"Ȅ" => "E",
"ȅ" => "e",
"Ȇ" => "E",
"ȇ" => "e",
"Ȉ" => "I",
"ȉ" => "i",
"Ȋ" => "I",
"ȋ" => "i",
"Ȍ" => "O",
"ȍ" => "o",
"Ȏ" => "O",
"ȏ" => "o",
"Ȑ" => "R",
"ȑ" => "r",
"Ȓ" => "R",
"ȓ" => "r",
"Ȕ" => "U",
"ȕ" => "u",
"Ȗ" => "U",
"ȗ" => "u",
"Ș" => "S",
"ș" => "s",
"Ț" => "T",
"ț" => "t",
"Ȝ" => "YOGH",
"ȝ" => "yogh",
"Ȟ" => "H",
"ȟ" => "h",
"Ƞ" => "N",
"ȡ" => "d",
"Ȣ" => "OU",
"ȣ" => "ou",
"Ȥ" => "Z",
"ȥ" => "z",
"Ȧ" => "A",
"ȧ" => "a",
"Ȩ" => "E",
"ȩ" => "e",
"Ȫ" => "O",
"ȫ" => "o",
"Ȭ" => "O",
"ȭ" => "o",
"Ȯ" => "O",
"ȯ" => "o",
"Ȱ" => "O",
"ȱ" => "o",
"Ȳ" => "Y",
"ȳ" => "y",
"ȴ" => "l",
"ȵ" => "n",
"ȶ" => "t",
"ȷ" => "j",
"ȸ" => "db",
"ȹ" => "qp",
"Ⱥ" => "A",
"Ȼ" => "C",
"ȼ" => "c",
"Ƚ" => "L",
"Ⱦ" => "T",
"ȿ" => "s",
"ɀ" => "z",
"Ɂ" => "STOP",
"ɂ" => "stop",
"Ƀ" => "B",
"Ʉ" => "U",
"Ʌ" => "V",
"Ɇ" => "E",
"ɇ" => "e",
"Ɉ" => "J",
"ɉ" => "j",
"Ɋ" => "Q",
"ɋ" => "q",
"Ɍ" => "R",
"ɍ" => "r",
"Ɏ" => "Y",
"ɏ" => "y",
"ɐ" => "a",
"ɑ" => "alpha",
"ɒ" => "alpha",
"ɓ" => "b",
"ɔ" => "o",
"ɕ" => "c",
"ɖ" => "d",
"ɗ" => "d",
"ɘ" => "e",
"ə" => "schwa",
"ɚ" => "schwa",
"ɛ" => "e",
"ɜ" => "e",
"ɝ" => "e",
"ɞ" => "e",
"ɟ" => "j",
"ɠ" => "g",
"ɡ" => "script",
"ɣ" => "gamma",
"ɤ" => "rams",
"ɥ" => "h",
"ɦ" => "h",
"ɧ" => "heng",
"ɨ" => "i",
"ɩ" => "iota",
"ɫ" => "l",
"ɬ" => "l",
"ɭ" => "l",
"ɮ" => "lezh",
"ɯ" => "m",
"ɰ" => "m",
"ɱ" => "m",
"ɲ" => "n",
"ɳ" => "n",
"ɵ" => "barred",
"ɷ" => "omega",
"ɸ" => "phi",
"ɹ" => "r",
"ɺ" => "r",
"ɻ" => "r",
"ɼ" => "r",
"ɽ" => "r",
"ɾ" => "r",
"ɿ" => "r",
"ʂ" => "s",
"ʃ" => "esh",
"ʄ" => "j",
"ʅ" => "squat",
"ʆ" => "esh",
"ʇ" => "t",
"ʈ" => "t",
"ʉ" => "u",
"ʊ" => "upsilon",
"ʋ" => "v",
"ʌ" => "v",
"ʍ" => "w",
"ʎ" => "y",
"ʐ" => "z",
"ʑ" => "z",
"ʒ" => "ezh",
"ʓ" => "ezh",
"ʚ" => "e",
"ʞ" => "k",
"ʠ" => "q",
"ʣ" => "dz",
"ʤ" => "dezh",
"ʥ" => "dz",
"ʦ" => "ts",
"ʧ" => "tesh",
"ʨ" => "tc",
"ʩ" => "feng",
"ʪ" => "ls",
"ʫ" => "lz",
"ʮ" => "h",
"ʯ" => "h")
药祭#氼 2024-12-03 23:55:21

我希望这对任何人都有用:
https://github.com/infralabs/DiacriticsRemovePHP

该类从包含 Latin-1 Suplement 的字符串中删除变音符号、拉丁文扩展 A 和拉丁文扩展 B 特殊字符。

用法:

$specialCharacters = "";
$specialCharacters .= "Latin-1 Supplement".PHP_EOL;
$specialCharacters .= "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ".PHP_EOL;
$specialCharacters .= "Latin Extended-A".PHP_EOL;
$specialCharacters .= "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ".PHP_EOL;
$specialCharacters .= "Latin Extended-B".PHP_EOL;
$specialCharacters .= "ƒǺǻǼǽǾǿ".PHP_EOL;
$specialCharacters .= "Latin Extended Additional".PHP_EOL;
$specialCharacters .= "ẀẁẂẃẄẅỲỳ".PHP_EOL;

print "<pre>";
print removeDiacritics($specialCharacters).PHP_EOL;
print "</pre>";

来源:

Latin-1 补充

<块引用>

ÀÁÂàäÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïïðñòóôõö÷øùúûüýþÿ

拉丁文扩展-A

<块引用>

大神们ĠġĢģĤĥĦħĨĩĪīĬĭĮįйвijĴĴĶķĸĹĺĻļĽľĿŀŁ ŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤ ťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ

拉丁语扩展-B

<块引用>

佟丽娅

拉丁语扩展附加

<块引用>

ẀẁẂẃẄẅỲỳ

结果:

Latin-1 补充

<块引用>

AAAAAECEEEEIIIIDNOOOOO×OUUUUYTHssaaaaaaaeceeeeeiiiidnooooo÷ouuuuythy

拉丁文扩展-A

<块引用>

AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkĸLllLllLllLllL NnNnNnnNnOoOoOoOEoeRrrRrrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs

拉丁语扩展-B

<块引用>

fAaAEaeOo

拉丁语扩展附加

<块引用>

WWWwWwYy

I hope this will be useful for anybody:
https://github.com/infralabs/DiacriticsRemovePHP

This class removes diacritics from strings containing Latin-1 Supplement, Latin Extended-A and Latin Extended-B special characters.

usage:

$specialCharacters = "";
$specialCharacters .= "Latin-1 Supplement".PHP_EOL;
$specialCharacters .= "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ".PHP_EOL;
$specialCharacters .= "Latin Extended-A".PHP_EOL;
$specialCharacters .= "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ".PHP_EOL;
$specialCharacters .= "Latin Extended-B".PHP_EOL;
$specialCharacters .= "ƒǺǻǼǽǾǿ".PHP_EOL;
$specialCharacters .= "Latin Extended Additional".PHP_EOL;
$specialCharacters .= "ẀẁẂẃẄẅỲỳ".PHP_EOL;

print "<pre>";
print removeDiacritics($specialCharacters).PHP_EOL;
print "</pre>";

source:

Latin-1 Supplement

ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ

Latin Extended-A

ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ

Latin Extended-B

ƒǺǻǼǽǾǿ

Latin Extended Additional

ẀẁẂẃẄẅỲỳ

result:

Latin-1 Supplement

AAAAAAAECEEEEIIIIDNOOOOO×OUUUUYTHssaaaaaaaeceeeeiiiidnooooo÷ouuuuythy

Latin Extended-A

AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkĸLlLlLlLlLlNnNnNnnNnOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs

Latin Extended-B

fAaAEaeOo

Latin Extended Additional

WwWwWwYy

时光磨忆 2024-12-03 23:55:21
function fn_normalize($s) { // Replaces all diacritics/accents
    return transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $s);
}

$a = [" Válue1  ", "válue2 ", "válue3", "Café à la carte", "A æ Übérmensch på høyeste nivå! И я люблю PHP! fi"];

$result = array_map('fn_normalize', $a);

var_dump($result);

这对我有用。您可能需要编辑 php.ini 的第 934 行,其中显示

;扩展名=intl

删除分号。

function fn_normalize($s) { // Replaces all diacritics/accents
    return transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $s);
}

$a = [" Válue1  ", "válue2 ", "válue3", "Café à la carte", "A æ Übérmensch på høyeste nivå! И я люблю PHP! fi"];

$result = array_map('fn_normalize', $a);

var_dump($result);

This worked for me. You might have to edit line 934 of your php.ini where it says

;extension=intl

Remove the semicolon.

那请放手 2024-12-03 23:55:21

解决此问题的最通用方法是使用 Unicode 规范化,因为它会自动处理所有重音 - 您不必预先准备清单。我不知道它在 PHP 中是否容易使用,我在 C 和 Java 中使用过它。本质上,您首先转换字符串,以便所有重音字符都由常规字符加上所谓的组合变音符号表示(内置或外部库应该提供此功能),然后删除组合变音符号(使用专门的库,使用语言提供的字符属性或使用一些正则表达式扩展)。

The most generic way to solve this is to use Unicode Normalization as it works automatically on all accents - you don't have to prepare the list up front. I don't know if it's easily available in PHP, I have used it in C and Java. Essentially, you first transform the string so that all accented characters are represented by regular character plus so-called composing diacritical mark (a built-in or external library should provide this function), and then remove the composing diacritics (using a specialized library, using character properties the language provides or using some regular expression extensions).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文