Jump to content

Recommended Posts

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|finaltext
ytext|ysomemoretext|yfinaltext

I'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.
Link to comment
https://forums.phpfreaks.com/topic/15194-deleting-row-in-text-file/
Share on other sites

[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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.