Jason Wong,您好! As you know,I'm a newbie in PHP,I tried your way last night,but to my surprise,it do nothing for any way,it didn't delete any line in the TXT-file,even the file "outputfile.txt" indeed! Perhaps it because that I haven't understand your thought and absolutely copy your words to the program,but,can you give me more help? After I write "del.php" copy your words,I'v been trying to edit my manage file "edit.php" as follow:
---filename:edit.php------------> <? $news=file('this.txt'); $num=count($news); $fp=fopen('outputfile','w'); echo "<TABLE>"; for($i=0;$i<$num;$i++){ echo "<tr><td>".$news[$i]."</td><td><a href=edit.php?action=del>删除此行</a></td></tr>"; if($action!='del')[EMAIL PROTECTED]($fp,$news[$i]); } echo "</table>ok"; fclose($fp);?> <-------------------------------- I think this will work as my willings,but it not! It's troubling so long.I need more help. Thanks a lot,my friend! ======= 2003-06-03 16:04:00 you wrote:======= >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 = = = = = = = = = = = = = = = = = = = = poetbox [EMAIL PROTECTED] 2003-06-04 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php