Re: about preg_replace, please help !
| From: | Daniel Brown | Date: | Mon, 04 Feb 2008 15:55:20 +0000 |
| Subject: | Re: about preg_replace, please help ! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-268640@lists.php.net to get a copy of this message | ||
On Feb 3, 2008 8:00 PM, LKSunny <ad@pc86.com> wrote:
> <?
> $txt = <<<eof
> aaaaaaaaa
> aaaaaaaaa
> aaaaaaaaa
>
> bbbbbbbb
> bbbbbbbb
>
> bbbbbbbb
> eof;
>
> //i just want replace "start to first \r\n\r\n"
> //how can i do ?
[snip]
<?
$txt = <<<eof
aaaaaaaaa
aaaaaaaaa
aaaaaaaaa
bbbbbbbb
bbbbbbbb
bbbbbbbb
eof;
$rep = preg_replace('/^(?s)(.*)(\r)?\n(\r)?\n/U','',$txt);
echo $rep."\n";
?>
Note the optional \r and required \n. This is because, if the
input/output is ever touching a non-Windows machine, it won't use \r\n
for newlines - only \n.
--
</Dan>
Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>