Posted by Rex on 11/18/08 11:43
Some observations: When reading a file you can use the funciton
feof() to check if a file pointer has reached the end of file marker.
This is useful when looping thru a file's contents.
I dont believe the inital fgets is needed -- just grab the first
line in the loop.
Also, instead of using the binary string comparision function use
the == operator and trim $contents to remove any uneeded whitespace
chars.
I'm not sure if the following listing is what you're looking for
as $strPretext only contains "#Text#" once the code is executed but i
think it's a step in the right direction.
If you're looking for the line after the "#Text#" line just do
another $content = fgets($fp); (line read) inside the if stmnt.
$filename = "/usr/local/file/rpt.txt";
$fp = fopen($filename, 'r');
$strPretext = "";
while( !feof($fp) ) {
$content = fgets($fp);
if( trim($content) == "#Text#") {
$strPretext .= $content;
}
}
echo $strPretext;
Navigation:
[Reply to this message]
|