note 7934 added to fgets

From: Date: Mon, 21 Aug 2000 08:09:53 +0000
Subject: note 7934 added to fgets
Groups: php.notes 
Request: Send a blank email to php-notes+get-2847@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"); ?> http://www.php.net/manual/function.fgets.php

« previous php.notes (#2847) next »