Read a file with filter, and give the output
am 27.08.2007 15:31:53 von innamorato.pazzo
Hi!
I would like to create a php script that read a txt file and filter it
with 2 keywords, first keyword deifne the start and the second one the
end of the txt to read.
And then give the output extracted.
Expter of the group, could you help me?
thanks!
Re: Read a file with filter, and give the output
am 27.08.2007 16:42:38 von burgermeister01
On Aug 27, 8:31 am, innamorato.pa...@gmail.com wrote:
> Hi!
> I would like to create a php script that read a txt file and filter it
> with 2 keywords, first keyword deifne the start and the second one the
> end of the txt to read.
> And then give the output extracted.
>
> Expter of the group, could you help me?
> thanks!
You might be looking for something like the following. I haven't
tested this, so I'm sure my string parsing is off by one, or
something. Also the variable names are kind of long for clarity's
sake; you may want to shorten them.
$file_path = "/path/to/file.txt";
$contents = file_get_contents($file_path);
$start_string_position = strpos($contents, "start");
$end_string_position = strpos($contents, "end",
$start_string_position);
$extracted_string_length = $end_string_position -
$start_string_position;
$extracted_string = substr($contents, $start_string_position,
$extracted_string_length);
Re: Read a file with filter, and give the output
am 27.08.2007 16:52:34 von gosha bine
On 27.08.2007 15:31 innamorato.pazzo@gmail.com wrote:
> Hi!
> I would like to create a php script that read a txt file and filter it
> with 2 keywords, first keyword deifne the start and the second one the
> end of the txt to read.
> And then give the output extracted.
>
> Expter of the group, could you help me?
> thanks!
>
preg_match('~start(.*?)end~s',
file_get_contents('filename'),
$matches
);
the output will be in $matches[1]
--
gosha bine
makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi