Cynosure.X International LLC

:

Add Comment | Related Links | TrackBack
Related Content

ereg functions are deprecated

While looking at the PHP online reference for ereg, I noticed a huge deprecation notice:

Warning

This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

Looks like all of the ereg functions (ereg_replace, etc.) are being removed in the new version of PHP. They are all deprecated in favor of the Perl-compatible functions:

Note: As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED notice.

My codes are littered with ereg functions. Having to port my code over to use the PCRE extension is not going to be fun.

Chieh Cheng
Wed, 24 Feb 2010 19:15:50 +0000

I found in many ereg_replace cases, you can simply surround the pattern with '/' when you convert to preg_replace. For example:

  $line = ereg_replace ('\n', '', $line);
$line = preg_replace ('/\n/', '', $line);

Chieh Cheng
Thu, 25 Feb 2010 09:27:14 +0000

eregi_replace is for case-insensitive replacements. To substitute preg_replace for this function call, you'll have to use the 'i' modifier. For example:

  $str = eregi_replace ("%7D", "}", $str);
$str = preg_replace ("/%7D/i", "}", $str);

Chieh Cheng
Mon, 12 Jul 2010 05:44:31 +0000

For many cases where you are not searching for regular expression replacements, you can simply substitute str_replace instead. For example:

  $str = ereg_replace (">", "%3E", $str);
$str = str_replace (">", "%3E", $str);

Chieh Cheng
Mon, 12 Jul 2010 05:47:47 +0000

If you use ereg to determine whether a string contains a regular expression, you can replace the ereg function with preg_match. For example:

  $result = ereg ("\[MOVED\] ", $this->pageTitle)
$result = preg_match ("/\[MOVED\] /", $this->pageTitle)

Chieh Cheng
Mon, 12 Jul 2010 06:39:55 +0000

Add Comment | Related Links | TrackBack
Related Content

Did your message disappear? Read the Forums FAQ.

Add Comment

Spam Control | * indicates required field
Your Name: *
E-mail:
Remember Me!
Comment: *
File attachment is optional. Please do not attach a file to your submission unless it is relevent.
Attach File:
(20 MB Max)
Spam Protection: * Answer of 5 + 9?
Click button only once, please!

TrackBack

TrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites.

Send Ping | TrackBack URL | Spam Control

No TrackBacks yet. TrackBack can be used to link this thread to your weblog, or link your weblog to this thread. In addition, TrackBack can be used as a form of remote commenting. Rather than posting the comment directly on this thread, you can posts it on your own weblog. Then have your weblog sends a TrackBack ping to the TrackBack URL, so that your post would show up here.

Messages, files, and images copyright by respective owners.

Products | Services
Forums | Latest | RSS
Library | Search | Wiki
Help | Licenses

Login | Register

80 Users Online

Hacking Digital Cameras
Fun for Photographers


Get Our

Memecoins!



Amazon Associate

Copyright © 1996 - 2024. All Rights Reserved.