Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP从CSV导入的数据具有断开的隐藏字符_Php_Mysql_Csv_Laravel_Csv Import - Fatal编程技术网

使用PHP从CSV导入的数据具有断开的隐藏字符

使用PHP从CSV导入的数据具有断开的隐藏字符,php,mysql,csv,laravel,csv-import,Php,Mysql,Csv,Laravel,Csv Import,我正在使用将CSV文件导入到我的应用程序中,并尝试将其数据与我的数据库相匹配 到目前为止,守则是: Excel::load($file, function($reader) { //Load it into Excel package $reader->each(function($row) { //Loop through row by row $firstname = $row->forename; $surname = $row->

我正在使用将CSV文件导入到我的应用程序中,并尝试将其数据与我的数据库相匹配

到目前为止,守则是:

Excel::load($file, function($reader) { //Load it into Excel package
    $reader->each(function($row) { //Loop through row by row

        $firstname = $row->forename;
        $surname = $row->surname;

        $firstname = str_replace('"', '', $firstname); //Remove the enclosure "
        $surname = str_replace('"', '', $surname);

        $client = DB::table('clients')->where('firstname', $firstname)->where('surname', $surname)->first();

        if ($client!=null) {
            print $client->id."<br><br><br>";
        } else {
            print "Fail<br><br><br>";
        }
    });
})->get();
如您所见,从CSV获取的所有字符串都有一个� 在每个字符之后

我想这可能是某种编码问题?我是否需要转义或处理CSV文件中的字符串,然后才能像普通PHP字符串一样使用它们


非常感谢您的帮助

请检查下面的代码,我在这里找到了相同的代码 检查“输入编码”部分 希望这有帮助

// When utilising a closure, you can pass the input encoding as third parameter.
Excel::load('filename.csv', function($reader) {

}, 'UTF-8');

请检查下面的代码,我在这里找到了相同的代码 检查“输入编码”部分 希望这有帮助

// When utilising a closure, you can pass the input encoding as third parameter.
Excel::load('filename.csv', function($reader) {

}, 'UTF-8');

对不起,我应该说我试过那个,但没用。对不起,我应该说我试过那个,但没用。