嗨,我有一个您无法解决的问题。事实证明,我正在尝试通过CSV
然后删除我选择的行,最后将其余的保存在其中CSV
。我的代码还没有完成。
数据内容示例.vsv
Goggle.com,2019/03/25,2019/04/25,30
Facebook. Com,2019/03/25,2019/04/25,30
Vk.com,2019/03/25,2019/04/25,30
Vídeos.com,2019/03/25,2019/04/25,30
Yahoo.com,2019/03/25,2019/04/25,30
Twitte.com,2019/03/25,2019/04/25,30
$remaining 变量是随机的,所以它可以是任何行
$restante= 0;
$handle = fopen("datos.csv", "r");
while ($linea = fgetcsv($handle, 0, ",")) {
$enlace = @$linea[0];
$fecha1 = @$linea[1];
$fecha2 = @$linea[2];
$restante = @$linea[3];
if($restante == 2){
//
}elseif($restante == 0){
//elimina el enlace
$linea[0] = null;
$linea[1] = null;
$linea[2] = null;
$linea[3] = null;
fputcsv($handle, array($linea[0], $linea[1], $linea[2], $linea[3]));
}
$linea[3] = $restante;
}
fclose($handle);
如您所见,代码尚未完成,因为我找不到删除该行并保存其余部分的方法。
更新
$handle = fopen("datos.csv", "w");
while ($linea = fgetcsv($handle, 0, ",")) {
$enlace = @$linea[0];
$fecha1 = @$linea[1];
$fecha2 = @$linea[2];
$restante = @$linea[3];
$restan = 0;
if($restan != 0){
echo " no se borro ninguna linea";
fputcsv($handle, array($enlace,$fecha1,$fecha2,$restan));
}else{
echo "linea borrada: " .$enlace;
}
}
fclose($handle);
有了这个表格,他没有给我任何信息,datos.csv
他把它留空
我期望的结果是等于 $remaining 的行从 data.csv 中删除
我希望你能给我一些想法。亲切的问候。
你可以这样做:
在你的情况下没有必要使用
fgetcsv
,因为你想删除整行而不是访问元素本身。