note 7934 deleted from function.fgets by sniper

From: Date: Sat, 08 Feb 2003 20:08:07 +0000
Subject: note 7934 deleted from function.fgets by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-43653@lists.php.net to get a copy of this message
This is an example for deleting N lines after an occurence of particular string: <? $filename = "./result.txt"; $fd = fopen ($filename, "r"); $query_str="Memory"; $m_line=5;$tmp_line=0;$line=0; $m_filename = "./result2.txt"; $m_fd = fopen($m_filename, "w"); while (!feof ($fd)) { $buffer = fgets($fd, 4096); $pos = strpos ($buffer, $query_str); if ($pos === false and $line==0) { fputs ($m_fd,$buffer); } else { if ($tmp_line < $m_line) { $tmp_line = $tmp_line + 1; $line = 1; } else { $line = 0; } } } fclose($fd); fclose($m_fd); copy("./result2.txt","./result.txt"); ?>

« previous php.notes (#43653) next »