RE: [PHP] ereg_replace to preg_replace translation
| From: | Ford, Mike | Date: | Tue, 11 Aug 2009 15:21:30 +0000 |
| Subject: | RE: [PHP] ereg_replace to preg_replace translation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296636@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: m a r k u s [mailto:queribus2000@hotmail.com]
> Sent: 11 August 2009 15:34
>
> 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);
Generally the only change you need to make for transition from ereg to preg (for simple expressions,
anyway) is the addition of pattern delimiters. So the above becomes, for example:
$sql = preg_replace("|\n#[^\n]*\n|", "", $sql);
Although I would argue that those \ characters should be escaped (and should have been even for
ereg), so the more correct version of this is:
$sql = preg_replace("|\\n#[^\\n]*\\n|", "", $sql);
Cheers!
Mike
--
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
Leeds Metropolitan University, C507, Civic Quarter Campus,
Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 812 4730
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm