|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hey guys, i'm new here (and new with php for that matter). Here is my problem.
I am creating a "note manager" as a way to learn php. Right now i'm using a form that updates a note, and puts it in a unique folder (based on date+time which is stored as an ID). The problem i'm having is that the notes are stored on a main page. I call this the "note register" where I can read the list of links that are linked to notes (in folders). Okay, so I have no problem creating a file within those folders which also deletes the folder (when called through a link), and all of its contents. Here's the kicker. I don't know how to delete a line of text. I know that's kinda sad but i've looked everywhere and googled for 2 days trying to figure this out. Nothing. Right now each line in the note registry is layed out in an HTML file which is called into the note register. (i use fputs(); to insert a new line when adding a note ; those lines are then read into the main document with a php include="file") but I cannot get rid of that line when I am done with the note. I just wanted to be able to delete the line when i'm done with it. It's only 1 line. (as a link) so : My file creates this... (fputs new lines here... from the form) <a herf="...">note line</a> <a herf="...">note line 2</a> <a herf="...">note line 3</a> <a herf="...">note line 4</a> but I want to then delete line 3 because it is out of date. In html the lines look like this <!--002211002211--><a herf="...">note line</a> <!--002211000235--><a herf="...">note line 2</a> <!--002211065888--><a herf="...">note line 3</a> <!--002211022454--><a herf="...">note line 4</a> Is there a way to script some kind of function to find the line that the id is on say <!--002211065888--> and then delete everything on that line? Any help is appreciated. I'm sorry I cannot provide more code worthy a response. I'm clueless and still learning. |
|
#2
|
||||
|
||||
|
Check into the string comparison functions, such as strstr(), strpos(), ereg(), eregi(), and preg_match(). Also look into fread(). Basically, you'll need to open your file, iterate over the lines (splitting the return of fread() on newlines and sticking them in an array is a good way), use a string comparison function to find the line you're wanting to delete, and add all lines but that one to a string that you then use to overwrite the original file. See how far you can get with these hints and check back in if you have questions.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
okay, now after 6 and a half hours of screwing around i've come up with this.
<?php $notecheck=fopen("$note/$note+note_check.php","w+"); fputs($notecheck," <?php \$file=\"../note_tables.php\"; \$fr=fopen(\$file,\"r\"); \$contents=fread(\$fr,filesize(\$file)); if (preg_match(\"/\$dateid/\", \"\$file\")) { echo \"Success - A match has been found!.\"; } else { echo \"Failure - A match was not found, try again.\"; } fclose(\$fr); // close the file ! // ?> "); fclose($notecheck); // close the file // // ?> The important part being the echo result. I've got it to recognize teh tag... now how would I instead delete that line instead of echo the result? Basically the above spawns a file that will check the file I want (note register) for that tag... but I want it to delete the entire line when it finds it. I'm not sure how to dow that. i've st ruggled with this damn thing for over 6 hours now... and i'm just wondering if someone, should they be able to figure this out in 5 minutes, help me to rewrite it so that it deletes the line when it's found. |
|
#4
|
||||
|
||||
|
Hmm, I've never seen anything quite like that, though you're basically on the right track. Here's an untested quick take that you'll probably need to tweak:
PHP Code:
|
|
#5
|
|||
|
|||
|
anothe quick way using file(filename)
$lines=file("../note_tables.php"); ... foreach($lines as $line){ //For each line, if $dateid not found, add it to a string. if(!preg_match("/" . $dateid . "/",$line)){ $newcontents .= $line . "\n"; } } ... |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > delete a specific text line (html) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|