PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 21st, 2004, 11:26 AM
corbendallas corbendallas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 4 corbendallas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face delete a specific text line (html)

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.

Reply With Quote
  #2  
Old June 21st, 2004, 12:08 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
  #3  
Old June 21st, 2004, 04:01 PM
corbendallas corbendallas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 4 corbendallas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old June 22nd, 2004, 08:01 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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:
 $file="../note_tables.php";
$fr=fopen($file,"r");
$contents=fread($fr,filesize($file));
$lines=split("\n",$contents); //Each line becomes an element in this array.
foreach($lines as $line){
    
//For each line, if $dateid not found, add it to a string.
    
if(!preg_match("/" $dateid "/",$line)){
      
$newcontents .= $line "\n";
    }
}

//Now write the revised contents back into a file (presumably you'd reopen the original file with the "w" flag and overwrite the old contents.
$notecheck=fopen($note "/" $note "+note_check.php","w");
fwrite($notecheck,$newcontents);
fclose($notecheck); 

Reply With Quote
  #5  
Old July 21st, 2004, 08:50 AM
alvin_2004 alvin_2004 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 alvin_2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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"
;
}
}

...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > delete a specific text line (html)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT