On Tuesday 03 June 2003 11:11, poetbox wrote: > I've been having trouble to delete a line from a TXT-file for days. > The content of the text file just like below: > ---------------------------begin==> > 00145|test|line1 > 00255|test|line1 > 01143|test|line1 > 00469|test|line1 > 10146|test|line1 > --------------------------<==end > > Every line begins with a random number.I read the file (named THIS.TXT) > from a simple program just like this: > > ---------------------------begin==> > $news=file("this.txt"); > $num=count($news); > > echo "<TABLE borderColor=#ffffff cellSpacing=0 cellPadding=0 width=100% > bgColor=#efefef border=1>"; for($i=0;$i<$num;$i++) > { > $message=explode("|",$news[$i]); > $id=$message[0]; > $title=$message[1]; > $time=$message[3]; > $bgcol = (($i % 2) == 0) ? "CCCCCC": "EEEEEE"; > echo "<tr bgcolor='#{$bgcol}'><td>※ <a > href=zcfgcont.php?id=$id>$title</a></td><td>"; echo "<a href=del.php>DELETE > THIS LINE</a>";//HOW TO WRITE THIS LINE??HOW TO achieve the function? echo > "</td></tr>"; > } > echo "</table>"; > --------------------------<==end > ################################################# > *********The PROBLEM is:How to WRITE A FILE named del.php or WRITE A > FUNCTION() to delete this line? My opinion is to read the content to a > array and write any line but" $id=$id" line,but I delete all the content > by this,what should I do? It's the first time I ask a question by the > MAIL-LIST,my Enlish is poor,sorry. Thank you very much in advance.
"... but I delete all the content by this" Why? In del.php you would read in the file using file() then write out any lines not beginning with $id. So something like: $news=file("this.txt"); $fp = fopen('outputfile', 'w'); foreach ($news as $line) { if (strpos($line, $_GET['id']) !== 0) { fwrite($fp, $line); } } fclose($fp); -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* Rule of Creative Research: (1) Never draw what you can copy. (2) Never copy what you can trace. (3) Never trace what you can cut out and paste down. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php