Re: ereg_replace to preg_replace translation
| From: | Shawn McKenzie | Date: | Tue, 11 Aug 2009 15:17:28 +0000 |
| Subject: | Re: ereg_replace to preg_replace translation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296634@lists.php.net to get a copy of this message | ||
m a r k u s wrote:
> Hi all,
>
> I see that from PHP 5.3.0 ereg_replace() function is deprecated and
> throws a warning.
> I would like to use the preg_replace() function as an alternative of
> ereg_replace() function but... can't undestand the "\n#[^\n]*\n"
> expression.
>
> $sql = ereg_replace("\n#[^\n]*\n", "", $sql);
>
> Any help for tranlation or alternative ?
> Thanks
>
> --
> m a r k u s
Here's a good regex tutorial: http://www.regular-expressions.info/
But to answer your question, \n#[^\n]*\n means the match must:
start with a newline(\n) followed by a pound sign (#) followed by 0 or
more characters (*) that are not a newline(^\n) all the way up to
another newline (\n).
To translate to preg I think all you need to do is give it delimiters,
but that may not be necessary, not sure. "|\n#[^\n]*\n|"
--
Thanks!
-Shawn
http://www.spidean.com