|
Posted by Erwin Moller on 11/18/36 11:43
yawnmoth wrote:
> Say I have the following file - dummy.txt:
>
> a 4treg
> a sdfas
> a 4egdsag
> b 1111
> a ergdsfg
> b 1111
> c waefasdf
>
> How would I go about removing all the lines that begin with a b? I
> thought the following script (which I wrote with the intention of
> replacing all such lines with the empty string) would but apparently it
> doesn't:
>
> <?
> $contents = file_get_contents('dummy.txt');
> echo "\r\n";
> echo preg_replace('/^b.*?\n/','',$contents);
> ?>
>
> Any ideas?
Hi,
Read this:
http://nl3.php.net/manual/en/reference.pcre.pattern.modifiers.php
So you could add the m modifier, like this:
echo preg_replace('/^b.*\\n/m','',$contents);
where:
^b means begins with b
..* means: anything untill end of line (\n) is reached
\\n means the end of line
and the m outside the // means that your string is treated the way you ment
too (see description at www.php.net).
Regards,
Erwin Moller
[Back to original message]
|