Solved

Function eregi() is deprecated

Posted on 2014-02-22
2
310 Views
Last Modified: 2014-02-23
I believe preg_match should be used. What will be the code? Thank you.


1) if(ereg("^[A-Za-z0-9_]{1,255}$",$this->username))

2) if(eregi("^[https?://.+\..+]{1,255}",$this->url))

3) if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",$this->email))

4) if(ereg("^[0-9]{1,6}$",$this->hits))

5)   if(eregi("^[https?://.+\..+]{1,255}",$this->url)
&& eregi("[.+\@.+\..+]{1,255}",$this->email)

Open in new window

0
Comment
Question by:seopti
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39879977
Usually this is as simple as changing to preg_match() by adding a regex delimiter and the appropriate flags.  Example:

"^[https?://.+\..+]{1,255}" for eregi() would become
"#^[https?://.+\..+]{1,255}#i" for preg_match()

Another example...
if(ereg("^[0-9]{1,6}$",$this->hits)) would become something like this:
"/^[0-9]{1,6}$/"

You may fine it easier to make the conversion if you write out the regular expressions in a way that self-explains the expression.  Example:
$rgx 
= '/'        // REGEX DELIMITER
. '^'        // AT START OF THE STRING
. '[0-9]'    // CHARACTER CLASS OF DIGITS ONLY
. '{1,6}'    // WITH LENGTH OF 1-6 CHARACTERS
. '$'        // AT END OF STRING
. '/'        // REGEX DELIMITER
;

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39879985
Here's another example.  Original ereg() expression:
"^[A-Za-z0-9_]{1,255}$"

Open in new window

Updated for preg-type expressions:
$rgx
= '#'       // REGEX DELIMITER
. '^'       // AT START OF STRING
. '['       // START CHARACTER CLSS
. 'A-Z'     // UPPER CASE ALPHA
. 'a-z'     // LOWER CASE ALPHA
. '0-9'     // NUMERIC DIGITS
. '_'       // THE UNDERSCORE
. ']'       // END OF CHARACTER CLASS
. '{1,255}' // LENGTH FROM 1 TO 255
. '$'       // AT END OF STRING
. '#'       // REGEX DELIMITER
;

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question