Re: How to get a certain line from a file
| From: | Goetz Lohmann | Date: | Tue, 04 Feb 2003 22:49:20 +0000 |
| Subject: | Re: How to get a certain line from a file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134341@lists.php.net to get a copy of this message | ||
The New Source schrieb:
> How can I get a certain line from a file?
>
> If I get a file in this way:
>
> $f =
> fopen("http://www.url.com/index.htm","r");
>
> How can I get a certain line of the file index.htm?
>
> I would need to get the line number 232, or lines from 232 to 238. How can I get this content?
>
> Thanx.
>
> Rodrigo
>
<?php
...
$fromline=232;
$tillline=238;
$fp=fopen("http://www.url.com/index.htm", "r");
// go to line 232
fseek($fp, $fromline);
// how many lines to read ?
$numlines=$tillline-$fromline;
$i=0
// read the lines
while (!feof($fp) && $i<$numlines) {
$str[$i]=fgets($fp, $maxlength); // read line into Array
$i++; // next line
}
// now all lines from 232 till 238 are in the array $str[]
...
?>
--
@ Goetz Lohmann, Germany | Web-Developer & Sys-Admin
\/ ------------------------------------------------------
() He's the fellow that people wonder what he does and
|| why the company needs him, until he goes on vacation.