php convert accented characters to html entities

Solutions on MaxInterview for php convert accented characters to html entities by the best coders in the world

showing results for - "php convert accented characters to html entities"
Ana Paula
01 Mar 2019
1public static function remove_accents($string, $german = false)
2    {
3        // Single letters
4        $single_fr = explode(" ", "À Á Â Ã Ä Å Ą Ă Ç Ć Č Ď Đ Ð È É Ê Ë Ę Ě Ğ Ì Í Î Ï İ Ł Ľ Ĺ Ñ Ń Ň Ò Ó Ô Õ Ö Ø Ő Ŕ Ř Š Ś Ş Ť Ţ Ù Ú Û Ü Ů Ű Ý Ž Ź Ż à á â ã ä å ą ă ç ć č ď đ è é ê ë ę ě ğ ì í î ï ı ł ľ ĺ ñ ń ň ð ò ó ô õ ö ø ő ŕ ř ś š ş ť ţ ù ú û ü ů ű ý ÿ ž ź ż");
5        $single_to = explode(" ", "A A A A A A A A C C C D D D E E E E E E G I I I I I L L L N N N O O O O O O O R R S S S T T U U U U U U Y Z Z Z a a a a a a a a c c c d d e e e e e e g i i i i i l l l n n n o o o o o o o o r r s s s t t u u u u u u y y z z z");
6        $single = array();
7        for ($i = 0; $i < count($single_fr); $i++) {
8            $single[$single_fr[$i]] = $single_to[$i];
9        }
10        // Ligatures
11        $ligatures = array("Æ" => "Ae", "æ" => "ae", "Œ" => "Oe", "œ" => "oe", "ß" => "ss");
12        // German umlauts
13        $umlauts = array("Ä" => "Ae", "ä" => "ae", "Ö" => "Oe", "ö" => "oe", "Ü" => "Ue", "ü" => "ue");
14        // Replace
15        $replacements = array_merge($single, $ligatures);
16        if ($german) $replacements = array_merge($replacements, $umlauts);
17        $string = strtr($string, $replacements);
18        return $string;
19    }