Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Read a file with filter, and give the output

 
   Database Help (Home) -> PHP RSS
Next:  Automatically formatting ActionScript with HTML  
Author Message
innamorato.pazzo

External


Since: Aug 27, 2007
Posts: 1



(Msg. 1) Posted: Mon Aug 27, 2007 1:31 pm
Post subject: Read a file with filter, and give the output
Archived from groups: comp>lang>php (more info?)

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!

 >> Stay informed about: Read a file with filter, and give the output 
Back to top
Login to vote
burgermeister01

External


Since: Aug 22, 2007
Posts: 11



(Msg. 2) Posted: Mon Aug 27, 2007 1:31 pm
Post subject: Re: Read a file with filter, and give the output [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Aug 27, 8:31 am, 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);

 >> Stay informed about: Read a file with filter, and give the output 
Back to top
Login to vote
gosha bine

External


Since: Dec 13, 2007
Posts: 240



(Msg. 3) Posted: Mon Aug 27, 2007 4:52 pm
Post subject: Re: Read a file with filter, and give the output [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 27.08.2007 15:31 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 Wink http://code.google.com/p/pihipi
 >> Stay informed about: Read a file with filter, and give the output 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Output XML file! - I have a XML variable (string). I want to output it to a XML file. I'm using <?php header("Content-type: application/gps"); header("Content-Disposition: attachment; filename=paring.xml"); print $xml; ?> But I get an error ...

Read a 'lot' of file - Hello folks, For my php script i will have to parse around 200 files, it would have been better to have in a database, but i have no control over it... I need to use regular expression to see if there is an occurrence in the file i am reading. Does..

When output file shows only text...what's the problem? - this post is not archived.

'grep' a file - output to browser not working - I cannot figure why this works fine at the command-line of the linux server, but will not output anything to the browser, and no errors in the error_log (syslog). The goal here is to have a page to enter a search term and grep or zgrep pattern matches in...

write output query to a cvs file - I would like to output a odbc query to a text file. I have the following php code but it isnt working. <? //conneccion $conn=odbc_connect('DBA','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT BKAR_INV_SONUM ...
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]