Re: remove all lines starting with b
- From: "yawnmoth" <terra1024@xxxxxxxxx>
- Date: 27 Mar 2006 09:46:16 -0800
Erwin Moller wrote:
yawnmoth wrote:
<snip>
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).
Thanks for the suggestion - that helped!
I tried modifyng it such that it'd delete all lines not begining with a
b but am once again having some difficulty...
First, here's the (new) script:
<?
$contents = file_get_contents('dummy.txt');
echo "\r\n";
echo preg_replace('/^(?!b).*?\n/m','',$contents);
?>
The (?!b) should, as I understand it, match everything but b. What
instead seems to be happening is that, when using the dummy.txt file
that was posted earlier, all lines begining with a are deleted, but the
lines with c are still there.
Now, I realize that in this example, I could just as effectively
replace (?!b) with [^b] but this approach fails if b is anything other
than a single character. (eg. if I wanted to replace b with
192.168.1.1, I couldn't use [^...] - I'd have to use something like
(?!b))
.
- Follow-Ups:
- Re: remove all lines starting with b
- From: yawnmoth
- Re: remove all lines starting with b
- From: yawnmoth
- Re: remove all lines starting with b
- References:
- remove all lines starting with b
- From: yawnmoth
- Re: remove all lines starting with b
- From: Erwin Moller
- remove all lines starting with b
- Prev by Date: Re: remove all lines starting with b
- Next by Date: LDAP PHP
- Previous by thread: Re: remove all lines starting with b
- Next by thread: Re: remove all lines starting with b
- Index(es):
Relevant Pages
|