preg_replace OR eregi_replace, difference?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

preg_replace OR eregi_replace, difference?

Post by phazorRise »

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.
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: preg_replace OR eregi_replace, difference?

Post by anantha »

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...
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: preg_replace OR eregi_replace, difference?

Post by Darhazer »

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
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

Re: preg_replace OR eregi_replace, difference?

Post by phazorRise »

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.
Post Reply