Reply to Re: remove all lines starting with b

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация