PHP - how to delete a row from CSV file ?

2 posts Page 1 of 1
Contributors
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

I want to delete a row from a CSV file, but I figured its not that simple... Can anyone make a function using this prototype ? :
Code: Select all
function delline($file,$str);
TYVM !!
http://vagex.com/?ref=25000
User avatar
rocky4126
VIP - Donator
VIP - Donator
Posts: 258
Joined: Mon Nov 16, 2009 7:39 pm

You could try
Code: Select all
function delline($file,$str){
	if(!$fp = fopen($file,"w+")){
		return false;
	}
	if(!$cont = fread($fp)){
		return false;
	}
	$cont = str_replace($str."\r\n","",$cont);
	if(!fwrite($fp,$cont)){
		return false;
	}
	if(!fclose($fp)){
		return false;
	}
	return true;
}
all of the return false; bits aren't needed and can be removed, it just makes the code more standardised with the PHP stuff.
Image
2 posts Page 1 of 1
Return to “Help & Support”