PHP法语字母enconding

时间:2016-08-18 08:59:12

标签: php encoding character-encoding character


目前,我正在使用PHP,我正在解析CSV并将其保存到DB。
我没有任何问题,只是我有一些法语字符,它没有正确显示。
我看了之前的所有问题,我尝试了所有建议的解决方案,但没有人解决我的问题....
此外,使用“utf8_encode”,它变得更难以理解。
在这里您可以找到该函数的所有代码:

if(date('l') == 'Thursday' or date('d') == 1)
    {
        $row = 1;
        if (($handle = fopen("C:/Users/ASUS/Downloads/Exemple_extraction.csv", "r")) !== FALSE)
        {
            $this->createTable();
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
            {
                if($row == 1){ $row++; continue; }
                $num = count($data);
                for ($c = 0; $c < $num; $c++)
                {
                    $dataa = (explode(';', $data[$c]));
                    $dest = str_replace(' ', '', $dataa['27']);
                    echo($dataa['27']);echo '<br>';
                    switch($dest)
                    {
                        case 'Investissement':
                            $destination = 'Investir';
                            break;

                        case 'Non défini':
                            $destination = '';
                            break;

                        case 'Résidence principale':
                            $destination = 'Habiter';
                            break;

                        case 'Résidence secondaire':
                            $destination = 'Habiter';
                            break;

                        default:
                            $destination = '';
                    }

                    $tLogt = str_replace(' ', '', $dataa['26']);
                    switch($tLogt)
                    {
                        case 'Studio':
                            $tLogt = 'studio';
                            break;

                        case '1/2 pièces':
                            $tLogt = '2P';
                            break;

                        case '2/3 pièces':
                            $tLogt = '3P';
                            break;

                        case '3/4 pièces':
                            $tLogt = '4P';
                            break;

                        default:
                            if($tLogt == '4/5 pièces' || $tLogt == '5/6 pièces' || $tLogt == '5P DUPLEX')
                            {
                                $tLogt = '5P+';
                            }
                    }

                    if(str_replace(' ', '', $dataa['9']) != '')
                    {
                        $cp = substr(str_replace(' ', '', $dataa['9']), 0, 2);
                    }
                    else
                    {
                        $cp = '';
                    }

                    DB::table(date('l') . '_' . date("d_m_Y"))
                        ->insert(['flReservataire' => $dataa['0'],
                            'flClient' => $dataa['1'],
                            'idProspect' => $dataa['2'],
                            'civility' => $dataa['3'],
                            'firstname' => $dataa['4'],
                            'lastname' => $dataa['5'],
                            'address1' => $dataa['6'],
                            'address2' => $dataa['7'],
                            'address3' => $dataa['8'],
                            'zipcode' => $dataa['9'],
                            'city' => $dataa['10'],
                            'codeInsee' => $dataa['11'],
                            'country' => $dataa['12'],
                            'flNpai' => $dataa['13'],
                            'phone' => $dataa['14'],
                            'workphone' => $dataa['15'],
                            'cellphone' => $dataa['16'],
                            'email1' => $dataa['17'],
                            'email2' => $dataa['18'],
                            'flStopMarketing' => $dataa['19'],
                            'age' => $dataa['20'],
                            'program' => $dataa['21'],
                            'region' => $dataa['22'],
                            'department' => $dataa['23'],
                            'seller' => $dataa['24'],
                            'typeLogt' => $dataa['25'],
                            'tailleLogt' => $dataa['26'],
                            'destination' => $dataa['27'],
                            'apport' => $dataa['28'],
                            'budget' => $dataa['29'],
                            'timelimit' => $dataa['30'],
                            'idOrigine' => $dataa['31'],
                            'typeContact' => $dataa['32'],
                            'typeAction' => $dataa['33'],
                            'dateAction' => $dataa['34'],
                            'comment' => $dataa['35'],
                            'typeActionFuture' => $dataa['36'],
                            'dateActionFuture' => $dataa['37'],
                            'levier' => $dataa['38'],
                            'support' => $dataa['39'],
                            'enreg' => $dataa['40'],
                            'destination_good' => $destination,
                            'typologie_good' => $tLogt,
                            'cp_good' => $cp,]);
                }
            }
            fclose($handle);
            $this->sendMail('emailSuccess');
        }
        else
        {
            $this->sendMail('emailError');
        }
    }


在所有的“回声”中,我遇到了问题..
还有其他建议吗?
非常感谢
亲切的问候

1 个答案:

答案 0 :(得分:0)

我的假设是CSV文件使用本地编码。要将其加载到正确的内部表示中,您必须使用本地编码中的iconv()(可能是某些ISO-8859或WIN-12xx)到UTF8。

另外,要找出正确的编码,请使用一些支持切换编码的体面文本编辑器。然后只需找到一个使源可读的选项。