ereg or preg
ereg or preg, whats the difference?
preg is faster and more powerfull
you can also find this manual , btw
The ereg functions support the POSIX regular expression standard. The preg functions are based on the regex syntax and functions used in the Perl language. The preg functions support a few more options -- as to whether it's faster than ereg, I don't know about that. I use the preg functions mainly because I learned Perl before I learned PHP.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in
Nation
eBookworm.us
@NogDog
-- from http://www.php.net/ereg
ereg
(PHP 3, PHP 4, PHP 5)
ereg -- Regular expression match
Description
int ereg ( string pattern, string string [, array ®s] )
Note: preg_match(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to ereg().
As pointed out above:ereg == POSIX
preg == PCRE
The most important difference (in my opinion) is that POSIX does not support lazy quantifiers.
Originally Posted by
themarty
preg is faster
Is that true?
Originally Posted by
bokeh
The most important difference (in my opinion) is that POSIX does not support lazy quantifiers.
What does that mean?
just take a look at the quote in my second post.
and if you don't believe that, you could always benchmark it yourself
he's probably refering to the fact that posix doesn't support non-greedy matching
Originally Posted by
themarty
just take a look at the quote in my second post.
and if you don't believe that, you could always benchmark it yourself
Benchmarking proves that statment to be completely untrue by a factor of 10x (even more with long strings).
One other difference is they match 2 different things. PCRE matches the first found left most match whereas POSIX matches the longest left most match.
PHP Code:
<?php
$regex = 'cat|category' ;
$target = 'category' ;
echo '<p>ereg: ' . ( ereg ( $regex , $target , $match )? $match [ 0 ] : 'false' ). '</p>' ; // category
echo '<p>preg: ' . ( preg_match ( '/' . $regex . '/' , $target , $match )? $match [ 0 ] : 'false' ). '</p>' ; // cat
?>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks