<ki*********@yahoo.com> wrote in message
news:39**************************@posting.google.c om...
hey yall
I want to read a text file and check for a special word on it, how can
I do that? Also I want to search for a special word such as "?>" and
write something on the line that preceeds it if u see what I mean.
thanx in advance
Pat
A simple solution to your first question could go a little something like
this:
<?php
$txtfile = file('text.txt');
$txtfile = implode('\n',$txtfile);
?>
Then run some sort of search function on $txtfile, such as strstr() or
preg_match().
The answer to your second question is a little more complicated because it
would probably involve a regexp. Suppose you wanted to create a line that
contained the words "A NEW LINE" before the special word...
<?php
$txtfile = <<<BLOCK
foo bar baz something something more
something else SPECIALWORD
BLOCK;
$txtfile = preg_replace( "/(\n.*)(SPECIALWORD)/", "\nA NEW LINE$1$2",
$txtfile );
?>
- JP