newprogram Posted December 8, 2009 Share Posted December 8, 2009 I have a txt file about 100kb how would I delete a line for example the text file look like jkdslfsdf|dsfjhdsjkhfkds|fjhsdjkhfkjds weruewu|dsifgsd|ewrtet werioweuior|gdhfgh|wqerwqer so if i want this line delete "weruewu|dsifgsd|ewrtet" Link to comment https://forums.phpfreaks.com/topic/184355-need-help-delete-line-from-txt-file/ Share on other sites More sharing options...
Alex Posted December 8, 2009 Share Posted December 8, 2009 $file = file('filename.txt'); $key = array_search('weruewu|dsifgsd|ewrtet', $file); if($key) unset($file[$key]); file_put_contents('filename.txt', implode("\n", $file)); file array_search unset file_put_contents Link to comment https://forums.phpfreaks.com/topic/184355-need-help-delete-line-from-txt-file/#findComment-973242 Share on other sites More sharing options...
newprogram Posted December 8, 2009 Author Share Posted December 8, 2009 worked great thank you $file = file('filename.txt'); $key = array_search('weruewu|dsifgsd|ewrtet', $file); if($key) unset($file[$key]); file_put_contents('filename.txt', implode("\n", $file)); file array_search unset file_put_contents Link to comment https://forums.phpfreaks.com/topic/184355-need-help-delete-line-from-txt-file/#findComment-973276 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.