[英]Delete a row with CSV?
I tried a lot of things, but none of them seems to work properly... I Tried replacing the string of the file with null but that's bugged... I didn't find any csv functions that delete a row in a csv file, can anyone make this, or suggest me how to do this ? 我尝试了很多事情,但似乎都无法正常工作...我试图用null替换文件的字符串,但这是错误的...我没有找到任何可删除csv文件中一行的csv函数。 ,有人可以做这个,还是建议我怎么做? I'm a bit of a beginner, but I got experience in C# and C++ so php isn't too hard!
我是一个初学者,但是我有C#和C ++的经验,因此php不太难!
Algorithm: 算法:
$in = fopen( 'file1.csv', 'r');
$out = fopen( 'file2.csv', 'w');
// Check whether they opened
while( $row = fgetcsv( $in, 10000)){
if( ... your condition ...){
continue;
}
fputcsv( $out, $row);
}
fclose( $in); fclose( $out);
function delete_line($id)
{
if($id)
{
$file_handle = fopen("your_file.csv", "w+");
$myCsv = array();
while (!feof($file_handle) )
{
$line_of_text = fgetcsv($file_handle, 1024);
if ($id != $line_of_text[0])
{
fputcsv($file_handle, $line_of_text);
}
}
fclose($file_handle);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.