使用PHP从CSV导入的数据具有断开的隐藏字符
我正在使用将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->
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');
对不起,我应该说我试过那个,但没用。对不起,我应该说我试过那个,但没用。