mcmuney Posted August 9, 2007 Share Posted August 9, 2007 I have a function where it writes data on a text file with an assigned id. For example, the text file looks like: data.txt 1|Hey 45|Hi 76|Hello What I'd like to do is add a function that will allow me to use the specific line that start with the id. For example: delete.php : On this file I will pass the id number and based on it, the function will go to the data.txt file and delete the specific row. So if I pass the id=45, it will remove that row ONLY and the data.txt file will look like below after removal: 1|Hey 76|Hello Any help will be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/64017-deleting-rows-on-text-file/ Share on other sites More sharing options...
pranav_kavi Posted August 9, 2007 Share Posted August 9, 2007 This may help u, 1)Open a temporary file in write mode. 2)Read each line of the file using fgets. 3)'explode' each line using '|' as delimiter 4)Only if the first token is not equal to 45,write that line to temporary file 5)Once all the lines have been checked,unlink the original file & rename the temporary file to name of the original file Link to comment https://forums.phpfreaks.com/topic/64017-deleting-rows-on-text-file/#findComment-319125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.