Mark Krenz wrote:
On Mon, Oct 12, 2009 at 05:55:25PM GMT, Carl P.
Corliss [rabbitt@gmail.com] said the following:Code Search of: "eregi?(replace)?( lang:php"
shows ~123,000 results
Code Search of:
"preg(filter|grep|last_error|match_all|match|quote|replace_callback|replace|split)(
lang:php" shows ~374,000 resultsLooks like preg_* functions are used more often
than ereg* functions to me...I think everyone should read this as it will
prove my point.
Especially book #9I have a O'Reilly Safari Books Online account and
can search the
content of many of the latest books, which I
consider something more
official than just doing a causual Google search,
which can be
misleading.The number 1 selling book on Amazon in the PHP
category is "PHP and
MySQL Web Development" (4th Edition) from 2008 by
Luke Welling and
Laura Thomson.There is no mention of preg_match and the book
instead shows how to
use ereg based functions. In fact, they do mention
PCRE, but downplay
it by saying that POSIX regexs are easier to use.I think any intelligent person would see this as a
alarm that the PHP
world isn't ready for ereg to be dropped or
changed. You need far more
time for the information to make its way through
the PHP community.Going further through the list of Amazon's top
selling PHP books we
have:
- The Essential Guide to Dreamweaver CS4 with CSS,
Ajax, and PHP (Essentials)Ignore this as it isn't really covering PHP properly.
- Regular Expression Pocket Reference: Regular
Expressions: from 2008This states that it covered PCRE expressions for
PHP. So at least
that's right.
- Learning PHP, MySQL, and JavaScript: A
Step-by-Step Guide to Creating
Dynamic Websites from 2009Uses examples written with preg_match
- Web Database Applications with PHP and MySQL,
2nd Edition from 2004.Mentions PCRE but says that they will use POSIX
expressions instead.
- Head First PHP & MySQL from 2008/2009
Talks about preg_match, mentions that ereg is
removed in PHP 6.
- PHP Cookbook from 2006
Has mixed examples, some using ereg and some
using preg_match
- Practical Web Practical Web 2.0
Applications with PHPNot on Safari
----> 9. Programming PHP by Kevin Tatroe, Rasmus
Lerdorf and Peter
MacIntyre in 2006. Which may be considered the
definitive guide to PHP
since Rasmus is a co-author.Uses examples with both ereg and preg_match, BUT
ereg is used first in
the book and compromises the majority of the
section called "Regular
Expressions". So here is an example of emphasis
being placed on ereg
being the more official functions to use.
- Wicked Cool PHP: Real-World Scripts That Solve
Difficult ProblemsNot on Safari
So that's about 4 out of 7 the top selling books on
PHP still strongly
use ereg. I didn't find any mention in the books I
read online about
ereg going away. Some of them supported PCRE more
than others. But
obviously there is still a lot of use of the POSIX
functions.
In PHP Cookbook, the only use of ereg I found was in
the section where the books was explaining how to
convert from ereg to preg_match. Or an occasional
mention that said you could do it with ereg but
preg_match was better. But, I might have missed
something.
Practical Web 2.0 Applications with PHP, published in
2008, uses PCRE functions.
Wicked Cool PHP, published in 2008, uses the PCRE
functions.
The book PHP & MySQL Web Development For Dummies,
published in 2008, uses only
PCRE funcitons. Doesn't even mention ereg. PHP &
MySQL for Dummies sells pretty well. Its fourth
edition will be released next month. It uses only
PCRE, does not mention ereg.
So, it appears that around 2007 most authors
recognized that they needed to begin moving readers
to the PCRE functions.
Janet
Mark Krenz wrote:
- PHP Cookbook from 2006
Has mixed examples, some using ereg and some using preg_match
In PHP Cookbook, the only use of ereg I found was in the section
where the books was explaining how to convert from ereg to
preg_match. Or an occasional mention that said you could do it with
ereg but preg_match was better. But, I might have missed something.
No. You are correct. We switched over all the examples to preg when we
revised the book for the second edition.
As we said in the introduction to our Regular Expressions chapter: "In
general, there's no longer any reason to use the ereg functions."
We also included a Recipe for converting from ereg to preg, including
how to use addcslashes()
to escape your delimiter, and dechex()
when
you're using an integer instead of a string as an input value for a
pattern or replacement (a valid, and highly useful case in some
instances, but very esoteric for most programs).
So, yes, there is some work that needs to be done to upgrade scripts,
and, yes, there are some dank corner cases, but they are relatively
straight forward to go after, shed light on, and clean up.
As someone who had to convert legacy code from PHP/FI to PHP 3, when
PHP changed its string contactenation operator, of all things, I can
say that subbing ereg() for preg() is an easier transition, especially
when it has the value of letting PHP 6 seamlessly support Unicode.
-adam
--
adam@trachtenberg.com | http://www.trachtenberg.com
author of o'reilly's "upgrading to php 5" and "php cookbook"
avoid the holiday rush, buy your copies today!