PHP replacing special characters like à->a, è->e

前端 未结 8 1772
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 14:20

I have php document signup.php which save the content from form (in form.php document) to MySQL base. The problem arises when I want to reformat the input content. I want do

8条回答
  •  旧巷少年郎
    2020-11-27 15:03

    Wish I found this thread sooner. The function I made (that took me way too long) is below:

    function CheckLetters($field){
        $letters = [
            0 => "a à á â ä æ ã å ā",
            1 => "c ç ć č",
            2 => "e é è ê ë ę ė ē",
            3 => "i ī į í ì ï î",
            4 => "l ł",
            5 => "n ñ ń",
            6 => "o ō ø œ õ ó ò ö ô",
            7 => "s ß ś š",
            8 => "u ū ú ù ü û",
            9 => "w ŵ",
            10 => "y ŷ ÿ",
            11 => "z ź ž ż",
        ];
        foreach ($letters as &$values){
            $newValue = substr($values, 0, 1);
            $values = substr($values, 2, strlen($values));
            $values = explode(" ", $values);
            foreach ($values as &$oldValue){
                while (strpos($field,$oldValue) !== false){
                    $field = preg_replace("/" . $oldValue . '/', $newValue, $field, 1);
                }
            }
        }
        return $field;
    }
    

提交回复
热议问题