note 7934 modified in function.fgets by irc-html

From: Date: Tue, 22 Jan 2002 23:06:08 +0000
Subject: note 7934 modified in function.fgets by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-25710@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"); ?> --was-- This is an example for deleting N lines after an occurence of particular string: &lt;? $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/en/function.fgets.php

« previous php.notes (#25710) next »