[英]Remove characters in array from file CSV PHP
Hey guys I'm geting a file CSV and when use print I have the output嘿伙计们,我得到了一个 CSV 文件,当使用 print 我有输出
$excelImoveis = $request->file('excel_imoveis');
$filePath = $excelImoveis->getRealPath();
$file = fopen($filePath, 'r');
$header = fgetcsv($file);
$array = [];
dd($header);
while (($columns = fgetcsv($file, 1000, ';')) !== FALSE) {
dd($header);
$array[] = array_combine(array_filter($header), array_filter($columns));
}
Outupu奥图普
array:1 [▼
0 => b"Código do Imóvel;FotoImovel;destaque;ordem"
]
How to remove "b" this item ?如何删除“b”这个项目? maybe this implied the error of array_conbine():
也许这暗示了 array_conbine() 的错误:
$array[] = array_combine(array_filter($header), array_filter($columns));
Error: array_combine(): Both parameters should have an equal number of elements错误:array_combine():两个参数应该有相同数量的元素
更改读取文件头的行以使用正确的分隔符
$header = fgetcsv($file, 1000, ';');
array_filter
removes empty-evaluated values (such as 0
, "0"
, ""
, null
, false
). array_filter
删除空评估值(例如0
、 "0"
、 ""
、 null
、 false
)。 So if one of your column has empty value, the number of elements will be different with header's and array_combine
will fail.因此,如果您的一列具有空值,则元素数量将与标题不同,并且
array_combine
将失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.