Hi, I want to know the difference between these two replace functions.
I know that, first two ie preg_replace and eregi_replace/ereg_replace are based on regular expressions.
I've used both two, they both are for same purpose.
Manual says, ereg_replace should be avoided if task can be done using str_replace or preg_replace.
I'm using this to extract BB codes from user comments and translating them into respective HTML identities.
SO what should I use for this purpose, preg_replace or eregi_replace?
Help is appreciated! Thank You.
preg_replace OR eregi_replace, difference?
Moderator: General Moderators
- phazorRise
- Forum Contributor
- Posts: 134
- Joined: Mon Dec 27, 2010 7:58 am
Re: preg_replace OR eregi_replace, difference?
eregi_replace is deprecated from php 5.3...so it is better to use preg_replace..since eregi_replace is deprecated i think most probably in next php version it will be removed...
Re: preg_replace OR eregi_replace, difference?
They both use regular expressions, but they have different syntax (preg use perl-compatible regular expressions while ereg uses POSIX regular expressions). In short, although simple regular expressions look the same way in both cases, preg have more advanced capabilities
- phazorRise
- Forum Contributor
- Posts: 134
- Joined: Mon Dec 27, 2010 7:58 am
Re: preg_replace OR eregi_replace, difference?
Darhazer wrote:They both use regular expressions, but they have different syntax (preg use perl-compatible regular expressions while ereg uses POSIX regular expressions). In short, although simple regular expressions look the same way in both cases, preg have more advanced capabilities
so i should prefer preg_replace.
Okay, thank you for response.