AncientSage Posted July 20, 2006 Share Posted July 20, 2006 Hello,Currently, I need to create a script that deletes a select row from a text file, at each \n character, that would mark a row...Now, let's say I have this for information... (in a text file)text|somemoretext|finaltextytext|ysomemoretext|yfinaltextI'd want my script to display that, which it does, but I'd also want the row number returned to the script, so it would know which row to delete. Any ideas how I'd do this? I could just use write, and re-write all the rows updated to the file, but if there is a way to just delete a row, then I'd like to take that path.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/15194-deleting-row-in-text-file/ Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 try the file() command, which will read the entire file into an array, with each row in it's own record. Quote Link to comment https://forums.phpfreaks.com/topic/15194-deleting-row-in-text-file/#findComment-61307 Share on other sites More sharing options...
Kurt Posted July 20, 2006 Share Posted July 20, 2006 [code]<?php$content=file_get_contents("file.txt");$rows=explode("\n",$content);?>[/code]Now, every row is in the $rows array. So, to access the first row you would do $rows[0]. To access the second row you would do $rows[1]. And, any other row after that, you know what to do. Quote Link to comment https://forums.phpfreaks.com/topic/15194-deleting-row-in-text-file/#findComment-61311 Share on other sites More sharing options...
AncientSage Posted July 20, 2006 Author Share Posted July 20, 2006 'k, thanks.Now, I have one more question...In a foreach loop, is it possible to exclude the last row? (Which is, blank.) Quote Link to comment https://forums.phpfreaks.com/topic/15194-deleting-row-in-text-file/#findComment-61343 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.