Замена акцентированных символов php

Я пытаюсь заменить акцентированные символы обычной заменой. Вот что я сейчас делаю.

$string = "Éric Cantona"; $strict = strtolower($string); echo "After Lower: ".$strict; $patterns[0] = '/[á|â|à|å|ä]/'; $patterns[1] = '/[ð|é|ê|è|ë]/'; $patterns[2] = '/[í|î|ì|ï]/'; $patterns[3] = '/[ó|ô|ò|ø|õ|ö]/'; $patterns[4] = '/[ú|û|ù|ü]/'; $patterns[5] = '/æ/'; $patterns[6] = '/ç/'; $patterns[7] = '/ß/'; $replacements[0] = 'a'; $replacements[1] = 'e'; $replacements[2] = 'i'; $replacements[3] = 'o'; $replacements[4] = 'u'; $replacements[5] = 'ae'; $replacements[6] = 'c'; $replacements[7] = 'ss'; $strict = preg_replace($patterns, $replacements, $strict); echo "Final: ".$strict; 

Это дает мне:

  • Подтверждение ввода пользователя, на стороне клиента или на стороне сервера?
  • Прямая трансляция видео с помощью PHP
  • подготовленные заявления - необходимы ли они
  • Как получить общее количество строк в CSV-файле с помощью PHP?
  • Загрузка, извлечение и повышение производительности PHP
  • Вызвать внешний скрипт оболочки из PHP и получить его идентификатор процесса
  •   After Lower: éric cantona Final: ric cantona 

    Вышеприведенное дает мне ric cantona Я хочу, чтобы выход был eric cantona .

    может ли кто-нибудь помочь мне, где я ошибаюсь?

    11 Solutions collect form web for “Замена акцентированных символов php”

    Я пробовал все виды, основанные на вариантах, перечисленных в ответах, но следующие работали:

     $unwanted_array = array( 'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' ); $str = strtr( $str, $unwanted_array ); 

    Чтобы удалить диакритические знаки, используйте значок:

     $val = iconv('ISO-8859-1','ASCII//TRANSLIT',$val); 

    или

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

    обратите внимание, что php имеет какую-то странную ошибку в том, что у нее (иногда?) должен быть установлен языковой стандарт, чтобы сделать эти преобразования, используя setlocale ().

    редактируйте только что испытанные, он получает большую часть ваших diacritics из коробки:

     $val = "á|â|à|å|ä ð|é|ê|è|ë í|î|ì|ï ó|ô|ò|ø|õ|ö ú|û|ù|ü æ ç ß abc ABC 123"; echo iconv('UTF-8','ASCII//TRANSLIT',$val); 

    вывод:

     a|a|a|a|a ?|e|e|e|ei|i|i|io|o|o|?|o|ou|u|u|u ae c ss abc ABC 123 

    Таким образом, вы можете вручную исправить эти два нечетных, прежде чем вызывать iconv, или вникать во внутренние действия php и на самом деле исправить это.

    Я только что получил ответ от Lizard, который очень полезен – особенно когда вы делаете какую-то сортировку. Разве не красиво, сколько символов нам нужно сказать в основном одинаково;)

    Если кто-либо еще ищет универсальное решение (что касается вышеприведенных комментариев), вот копия и вставка:

     /** * Replace language-specific characters by ASCII-equivalents. * @param string $s * @return string */ public static function normalizeChars($s) { $replace = array( 'ъ'=>'-', 'Ь'=>'-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Ǖ'=>'u', 'ǔ'=>'u', 'Ǜ'=>'u', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'У'=>'u', 'ǚ'=>'u', 'ǜ'=>'u', 'Ǚ'=>'u', 'Ǘ'=>'u', 'ǖ'=>'u', 'ǘ'=>'u', 'ü'=>'ue', 'в'=>'v', 'ו'=>'v', 'В'=>'v', 'ש'=>'w', 'ŵ'=>'w', 'Ŵ'=>'w', 'ы'=>'y', 'ŷ'=>'y', 'ý'=>'y', 'ÿ'=>'y', 'Ÿ'=>'y', 'Ŷ'=>'y', 'Ы'=>'y', 'ž'=>'z', 'З'=>'z', 'з'=>'z', 'ź'=>'z', 'ז'=>'z', 'ż'=>'z', 'ſ'=>'z', 'Ж'=>'zh', 'ж'=>'zh' ); return strtr($s, $replace); } 

    Обратите внимание на некоторые незначительные изменения в отношении немецких умляутов (ä => ae)

    Изменить: добавлено больше символов на основе публикации с user3682119 (за исключением символа авторского права) и комментария от daker.

    В PHP 5.4 расширение intl предоставляет новый класс с именем Transliterator.

    Я считаю, что это лучший способ удалить диакритические знаки по двум причинам:

    1. Транслитератор основан на ICU, поэтому вы используете таблицы библиотеки ICU. ОИТ – отличный проект, разработанный в течение года для обеспечения всеобъемлющих таблиц и функциональных возможностей. Независимо от того, какую таблицу вы хотите написать себе, она никогда не будет такой полной, как та, которая была бы от ICU.

    2. В UTF-8 символы могут быть представлены по-разному. Например, символ – может быть сохранен как один (многобайтовый) символ или как комбинация символов ˜ (многобайтовый) и n . В дополнение к этому некоторые символы в Юникоде являются гомографом: они выглядят одинаково, имея разные кодовые точки. По этой причине также важно нормализовать строку.

    Вот пример кода, взятый из моего старого ответа :

     <?php $transliterator = Transliterator::createFromRules(':: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD); $test = ['abcd', 'èe', '€', 'àòùìéëü', 'àòùìéëü', 'tiësto']; foreach($test as $e) { $normalized = $transliterator->transliterate($e); echo $e. ' --> '.$normalized."\n"; } ?> 

    Результат:

     abcd --> abcd èe --> ee € --> € àòùìéëü --> aouieeu àòùìéëü --> aouieeu tiësto --> tiesto 

    Первый аргумент для класса Transliterator выполняет удаление диакритики, а также нормализацию строки.

     protected $_convertTable = array( '&amp;' => 'and', '@' => 'at', '©' => 'c', '®' => 'r', 'À' => 'a', 'Á' => 'a', 'Â' => 'a', 'Ä' => 'a', 'Å' => 'a', 'Æ' => 'ae','Ç' => 'c', 'È' => 'e', 'É' => 'e', 'Ë' => 'e', 'Ì' => 'i', 'Í' => 'i', 'Î' => 'i', 'Ï' => 'i', 'Ò' => 'o', 'Ó' => 'o', 'Ô' => 'o', 'Õ' => 'o', 'Ö' => 'o', 'Ø' => 'o', 'Ù' => 'u', 'Ú' => 'u', 'Û' => 'u', 'Ü' => 'u', 'Ý' => 'y', 'ß' => 'ss','à' => 'a', 'á' => 'a', 'â' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae','ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ý' => 'y', 'þ' => 'p', 'ÿ' => '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', 'IJ' => 'ij','ij' => 'ij','Ĵ' => 'j', 'ĵ' => 'j', 'Ķ' => 'k', 'ķ' => 'k', 'ĸ' => 'k', 'Ĺ' => 'l', 'ĺ' => 'l', 'Ļ' => 'l', 'ļ' => 'l', 'Ľ' => 'l', 'ľ' => 'l', 'Ŀ' => 'l', 'ŀ' => 'l', 'Ł' => 'l', 'ł' => 'l', 'Ń' => 'n', 'ń' => 'n', 'Ņ' => 'n', 'ņ' => 'n', 'Ň' => 'n', 'ň' => 'n', 'ʼn' => 'n', 'Ŋ' => 'n', 'ŋ' => 'n', 'Ō' => 'o', 'ō' => 'o', 'Ŏ' => 'o', 'ŏ' => 'o', 'Ő' => 'o', 'ő' => 'o', 'Œ' => 'oe','œ' => 'oe','Ŕ' => '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', 'ſ' => 'z', 'Ə' => 'e', 'ƒ' => 'f', 'Ơ' => 'o', 'ơ' => 'o', 'Ư' => 'u', 'ư' => 'u', 'Ǎ' => 'a', 'ǎ' => 'a', 'Ǐ' => 'i', 'ǐ' => 'i', 'Ǒ' => 'o', 'ǒ' => 'o', 'Ǔ' => 'u', 'ǔ' => 'u', 'Ǖ' => 'u', 'ǖ' => 'u', 'Ǘ' => 'u', 'ǘ' => 'u', 'Ǚ' => 'u', 'ǚ' => 'u', 'Ǜ' => 'u', 'ǜ' => 'u', 'Ǻ' => 'a', 'ǻ' => 'a', 'Ǽ' => 'ae','ǽ' => 'ae','Ǿ' => 'o', 'ǿ' => 'o', 'ə' => 'e', 'Ё' => 'jo','Є' => 'e', 'І' => 'i', 'Ї' => 'i', 'А' => 'a', 'Б' => 'b', 'В' => 'v', 'Г' => 'g', 'Д' => 'd', 'Е' => 'e', 'Ж' => 'zh','З' => 'z', 'И' => 'i', 'Й' => 'j', 'К' => 'k', 'Л' => 'l', 'М' => 'm', 'Н' => 'n', 'О' => 'o', 'П' => 'p', 'Р' => 'r', 'С' => 's', 'Т' => 't', 'У' => 'u', 'Ф' => 'f', 'Х' => 'h', 'Ц' => 'c', 'Ч' => 'ch','Ш' => 'sh','Щ' => 'sch', 'Ъ' => '-', 'Ы' => 'y', 'Ь' => '-', 'Э' => 'je','Ю' => 'ju','Я' => 'ja', 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ж' => 'zh','з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch', 'ш' => 'sh','щ' => 'sch','ъ' => '-','ы' => 'y', 'ь' => '-', 'э' => 'je', 'ю' => 'ju','я' => 'ja','ё' => 'jo','є' => 'e', 'і' => 'i', 'ї' => 'i', 'Ґ' => 'g', 'ґ' => 'g', 'א' => 'a', 'ב' => 'b', 'ג' => 'g', 'ד' => 'd', 'ה' => 'h', 'ו' => 'v', 'ז' => 'z', 'ח' => 'h', 'ט' => 't', 'י' => 'i', 'ך' => 'k', 'כ' => 'k', 'ל' => 'l', 'ם' => 'm', 'מ' => 'm', 'ן' => 'n', 'נ' => 'n', 'ס' => 's', 'ע' => 'e', 'ף' => 'p', 'פ' => 'p', 'ץ' => 'C', 'צ' => 'c', 'ק' => 'q', 'ר' => 'r', 'ש' => 'w', 'ת' => 't', '™' => 'tm', ); 

    Из magento, im, используя его для всего

    Поэтому я нашел это на странице php.net для функции preg_replace

     // replace accented chars $string = "Zacarías Ferreíra"; // my definition for string variable $accents = '/&([A-Za-z]{1,2})(grave|acute|circ|cedil|uml|lig);/'; $string_encoded = htmlentities($string,ENT_NOQUOTES,'UTF-8'); $string = preg_replace($accents,'$1',$string_encoded); 

    Если у вас проблемы с кодировкой, вы можете получить такую ​​информацию, как этот «ZacarÃÂas FerreÃÂra», просто расшифруйте строку и используйте указанный выше код

     $string = utf8_decode("ZacarÃÂas FerreÃÂra"); 

    Обновленный ответ, основанный на ответе @BurninLeo

     function replace_spec_char($subject) { $char_map = array( "ъ" => "-", "ь" => "-", "Ъ" => "-", "Ь" => "-", "А" => "A", "Ă" => "A", "Ǎ" => "A", "Ą" => "A", "À" => "A", "Ã" => "A", "Á" => "A", "Æ" => "A", "Â" => "A", "Å" => "A", "Ǻ" => "A", "Ā" => "A", "א" => "A", "Б" => "B", "ב" => "B", "Þ" => "B", "Ĉ" => "C", "Ć" => "C", "Ç" => "C", "Ц" => "C", "צ" => "C", "Ċ" => "C", "Č" => "C", "©" => "C", "ץ" => "C", "Д" => "D", "Ď" => "D", "Đ" => "D", "ד" => "D", "Ð" => "D", "È" => "E", "Ę" => "E", "É" => "E", "Ë" => "E", "Ê" => "E", "Е" => "E", "Ē" => "E", "Ė" => "E", "Ě" => "E", "Ĕ" => "E", "Є" => "E", "Ə" => "E", "ע" => "E", "Ф" => "F", "Ƒ" => "F", "Ğ" => "G", "Ġ" => "G", "Ģ" => "G", "Ĝ" => "G", "Г" => "G", "ג" => "G", "Ґ" => "G", "ח" => "H", "Ħ" => "H", "Х" => "H", "Ĥ" => "H", "ה" => "H", "I" => "I", "Ï" => "I", "Î" => "I", "Í" => "I", "Ì" => "I", "Į" => "I", "Ĭ" => "I", "I" => "I", "И" => "I", "Ĩ" => "I", "Ǐ" => "I", "י" => "I", "Ї" => "I", "Ī" => "I", "І" => "I", "Й" => "J", "Ĵ" => "J", "ĸ" => "K", "כ" => "K", "Ķ" => "K", "К" => "K", "ך" => "K", "Ł" => "L", "Ŀ" => "L", "Л" => "L", "Ļ" => "L", "Ĺ" => "L", "Ľ" => "L", "ל" => "L", "מ" => "M", "М" => "M", "ם" => "M", "Ñ" => "N", "Ń" => "N", "Н" => "N", "Ņ" => "N", "ן" => "N", "Ŋ" => "N", "נ" => "N", "ʼn" => "N", "Ň" => "N", "Ø" => "O", "Ó" => "O", "Ò" => "O", "Ô" => "O", "Õ" => "O", "О" => "O", "Ő" => "O", "Ŏ" => "O", "Ō" => "O", "Ǿ" => "O", "Ǒ" => "O", "Ơ" => "O", "פ" => "P", "ף" => "P", "П" => "P", "ק" => "Q", "Ŕ" => "R", "Ř" => "R", "Ŗ" => "R", "ר" => "R", "Р" => "R", "®" => "R", "Ş" => "S", "Ś" => "S", "Ș" => "S", "Š" => "S", "С" => "S", "Ŝ" => "S", "ס" => "S", "Т" => "T", "Ț" => "T", "ט" => "T", "Ŧ" => "T", "ת" => "T", "Ť" => "T", "Ţ" => "T", "Ù" => "U", "Û" => "U", "Ú" => "U", "Ū" => "U", "У" => "U", "Ũ" => "U", "Ư" => "U", "Ǔ" => "U", "Ų" => "U", "Ŭ" => "U", "Ů" => "U", "Ű" => "U", "Ǖ" => "U", "Ǜ" => "U", "Ǚ" => "U", "Ǘ" => "U", "В" => "V", "ו" => "V", "Ý" => "Y", "Ы" => "Y", "Ŷ" => "Y", "Ÿ" => "Y", "Ź" => "Z", "Ž" => "Z", "Ż" => "Z", "З" => "Z", "ז" => "Z", "S" => "Z", "а" => "a", "ă" => "a", "ǎ" => "a", "ą" => "a", "à" => "a", "ã" => "a", "á" => "a", "æ" => "a", "â" => "a", "å" => "a", "ǻ" => "a", "ā" => "a", "א" => "a", "б" => "b", "ב" => "b", "þ" => "b", "ĉ" => "c", "ć" => "c", "ç" => "c", "ц" => "c", "צ" => "c", "ċ" => "c", "č" => "c", "©" => "c", "ץ" => "c", "Ч" => "ch", "ч" => "ch", "д" => "d", "ď" => "d", "đ" => "d", "ד" => "d", "ð" => "d", "è" => "e", "ę" => "e", "é" => "e", "ë" => "e", "ê" => "e", "е" => "e", "ē" => "e", "ė" => "e", "ě" => "e", "ĕ" => "e", "є" => "e", "ə" => "e", "ע" => "e", "ф" => "f", "ƒ" => "f", "ğ" => "g", "ġ" => "g", "ģ" => "g", "ĝ" => "g", "г" => "g", "ג" => "g", "ґ" => "g", "ח" => "h", "ħ" => "h", "х" => "h", "ĥ" => "h", "ה" => "h", "i" => "i", "ï" => "i", "î" => "i", "í" => "i", "ì" => "i", "į" => "i", "ĭ" => "i", "ı" => "i", "и" => "i", "ĩ" => "i", "ǐ" => "i", "י" => "i", "ї" => "i", "ī" => "i", "і" => "i", "й" => "j", "Й" => "j", "Ĵ" => "j", "ĵ" => "j", "ĸ" => "k", "כ" => "k", "ķ" => "k", "к" => "k", "ך" => "k", "ł" => "l", "ŀ" => "l", "л" => "l", "ļ" => "l", "ĺ" => "l", "ľ" => "l", "ל" => "l", "מ" => "m", "м" => "m", "ם" => "m", "ñ" => "n", "ń" => "n", "н" => "n", "ņ" => "n", "ן" => "n", "ŋ" => "n", "נ" => "n", "ʼn" => "n", "ň" => "n", "ø" => "o", "ó" => "o", "ò" => "o", "ô" => "o", "õ" => "o", "о" => "o", "ő" => "o", "ŏ" => "o", "ō" => "o", "ǿ" => "o", "ǒ" => "o", "ơ" => "o", "פ" => "p", "ף" => "p", "п" => "p", "ק" => "q", "ŕ" => "r", "ř" => "r", "ŗ" => "r", "ר" => "r", "р" => "r", "®" => "r", "ş" => "s", "ś" => "s", "ș" => "s", "š" => "s", "с" => "s", "ŝ" => "s", "ס" => "s", "т" => "t", "ț" => "t", "ט" => "t", "ŧ" => "t", "ת" => "t", "ť" => "t", "ţ" => "t", "ù" => "u", "û" => "u", "ú" => "u", "ū" => "u", "у" => "u", "ũ" => "u", "ư" => "u", "ǔ" => "u", "ų" => "u", "ŭ" => "u", "ů" => "u", "ű" => "u", "ǖ" => "u", "ǜ" => "u", "ǚ" => "u", "ǘ" => "u", "в" => "v", "ו" => "v", "ý" => "y", "ы" => "y", "ŷ" => "y", "ÿ" => "y", "ź" => "z", "ž" => "z", "ż" => "z", "з" => "z", "ז" => "z", "ſ" => "z", "™" => "tm", "@" => "at", "Ä" => "ae", "Ǽ" => "ae", "ä" => "ae", "æ" => "ae", "ǽ" => "ae", "ij" => "ij", "IJ" => "ij", "я" => "ja", "Я" => "ja", "Э" => "je", "э" => "je", "ё" => "jo", "Ё" => "jo", "ю" => "ju", "Ю" => "ju", "œ" => "oe", "Œ" => "oe", "ö" => "oe", "Ö" => "oe", "щ" => "sch", "Щ" => "sch", "ш" => "sh", "Ш" => "sh", "ß" => "ss", "Ü" => "ue", "Ж" => "zh", "ж" => "zh", ); return strtr($subject, $char_map); } $string = "Ħí ŧħə®ë, юßť å test!"; echo replace_spec_char($string); 

    Ħí ŧħə®ë, юßť å test! => Hi there, jusst a test!

    This does not mix up upper and lower case chars except for longer chars (eg: ss,ch, sch) , added @ ® ©

    Also if you want to build regex matching regardless to special chars :

    rss => '[rŕřŘŗŖרŔРр](?:[sșсŜšśסşСŝ][sșсŜšśסşСŝ]|[ß])'

    A vala implementation of this : https://code.launchpad.net/~jeremy-munsch/synapse-project/ascii-smart/+merge/277477

    Here is the base list you could work with, with regex replacing (in sublime text) or small script you can build anything from this array to fill your needs.

     "-" => "ъьЪЬ", "A" => "АĂǍĄÀÃÁÆÂÅǺĀא", "B" => "БבÞ", "C" => "ĈĆÇЦצĊČ©ץ", "D" => "ДĎĐדÐ", "E" => "ÈĘÉËÊЕĒĖĚĔЄƏע", "F" => "ФƑ", "G" => "ĞĠĢĜГגҐ", "H" => "חĦХĤה", "I" => "IÏÎÍÌĮĬIИĨǏיЇĪІ", "J" => "ЙĴ", "K" => "ĸכĶКך", "L" => "ŁĿЛĻĹĽל", "M" => "מМם", "N" => "ÑŃНŅןŊנʼnŇ", "O" => "ØÓÒÔÕОŐŎŌǾǑƠ", "P" => "פףП", "Q" => "ק", "R" => "ŔŘŖרР®", "S" => "ŞŚȘŠСŜס", "T" => "ТȚטŦתŤŢ", "U" => "ÙÛÚŪУŨƯǓŲŬŮŰǕǛǙǗ", "V" => "Вו", "Y" => "ÝЫŶŸ", "Z" => "ŹŽŻЗזS", "a" => "аăǎąàãáæâåǻāא", "b" => "бבþ", "c" => "ĉćçцצċč©ץ", "ch" => "ч", "d" => "дďđדð", "e" => "èęéëêеēėěĕєəע", "f" => "фƒ", "g" => "ğġģĝгגґ", "h" => "חħхĥה", "i" => "iïîíìįĭıиĩǐיїīі", "j" => "йĵ", "k" => "ĸכķкך", "l" => "łŀлļĺľל", "m" => "מмם", "n" => "ñńнņןŋנʼnň", "o" => "øóòôõоőŏōǿǒơ", "p" => "פףп", "q" => "ק", "r" => "ŕřŗרр®", "s" => "şśșšсŝס", "t" => "тțטŧתťţ", "u" => "ùûúūуũưǔųŭůűǖǜǚǘ", "v" => "вו", "y" => "ýыŷÿ", "z" => "źžżзזſ", "tm" => "™", "at" => "@", "ae" => "ÄǼäæǽ", "ch" => "Чч", "ij" => "ijIJ", "j" => "йЙĴĵ", "ja" => "яЯ", "je" => "Ээ", "jo" => "ёЁ", "ju" => "юЮ", "oe" => "œŒöÖ", "sch" => "щЩ", "sh" => "шШ", "ss" => "ß", "tm" => "™", "ue" => "Ü", "zh" => "Жж" 

    strtolower only works on iso-8859-1 encoded strings. You could try with mb_strtolower .

    Or, if you have to mangle with multibyte-extensions, you might as well use iconv's transliteration support:

     iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text); 

    Редактировать:

    It seems I was a bit fast. You appear to use iso-8859-1, so your current strategy will work. You just need to write the regexp's properly. Например.:

     '/(ð|é|ê|è|ë)/' 

    not:

     '/[ð|é|ê|è|ë]/' 

    Это сработало для меня:

     <?php setlocale(LC_ALL, "en_US.utf8"); $val = iconv('UTF-8','ASCII//TRANSLIT',$val); ?> 

    I know, that question has been asked a long long time ago…

    I was looking for a short and elegant solution, but couldn't find satisfaction for two reasons:

    First, most of the existing solutions replace a list of characters by a list of other characters. Unfortunately, it require to use a specific encoding for the php script file itself which might be unwanted.

    Second, using iconv seems to be a good way, but it's not enough as the result of a converted character could be one or two characters, or a Fatal Exception.

    So I wrote that small function which does the job :

     function replaceAccent($string, $replacement = '_') { $alnumPattern = '/^[a-zA-Z0-9 ]+$/'; if (preg_match($alnumPattern, $string)) { return $string; } $ret = array_map( function ($chr) use ($alnumPattern, $replacement) { if (preg_match($alnumPattern, $chr)) { return $chr; } else { $chr = @iconv('ISO-8859-1', 'ASCII//TRANSLIT', $chr); if (strlen($chr) == 1) { return $chr; } elseif (strlen($chr) > 1) { $ret = ''; foreach (str_split($chr) as $char2) { if (preg_match($alnumPattern, $char2)) { $ret .= $char2; } } return $ret; } else { // replace whatever iconv fail to convert by something else return $replacement; } } }, str_split($string) ); return implode($ret); } } else { function replaceAccent($string, $replacement = '_') { $alnumPattern = '/^[a-zA-Z0-9 ]+$/'; if (preg_match($alnumPattern, $string)) { return $string; } $ret = array_map( function ($chr) use ($alnumPattern, $replacement) { if (preg_match($alnumPattern, $chr)) { return $chr; } else { $chr = @iconv('ISO-8859-1', 'ASCII//TRANSLIT', $chr); if (strlen($chr) == 1) { return $chr; } elseif (strlen($chr) > 1) { $ret = ''; foreach (str_split($chr) as $char2) { if (preg_match($alnumPattern, $char2)) { $ret .= $char2; } } return $ret; } else { // replace whatever iconv fail to convert by something else return $replacement; } } }, str_split($string) ); return implode($ret); } } else { function replaceAccent($string, $replacement = '_') { $alnumPattern = '/^[a-zA-Z0-9 ]+$/'; if (preg_match($alnumPattern, $string)) { return $string; } $ret = array_map( function ($chr) use ($alnumPattern, $replacement) { if (preg_match($alnumPattern, $chr)) { return $chr; } else { $chr = @iconv('ISO-8859-1', 'ASCII//TRANSLIT', $chr); if (strlen($chr) == 1) { return $chr; } elseif (strlen($chr) > 1) { $ret = ''; foreach (str_split($chr) as $char2) { if (preg_match($alnumPattern, $char2)) { $ret .= $char2; } } return $ret; } else { // replace whatever iconv fail to convert by something else return $replacement; } } }, str_split($string) ); return implode($ret); } 

    if you have http://php.net/manual/en/book.intl.php available, this will solve your problem:

     $string = "Éric Cantona"; $transliterator = Transliterator::createFromRules(':: NFD; :: [:Nonspacing Mark:] Remove; :: Lower(); :: NFC;', Transliterator::FORWARD); echo $normalized = $transliterator->transliterate($string); 
    PHP is the Best Programming Language in the world.