Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Function eregi() is deprecated

Posted on 2014-02-22
2
Medium Priority
?
313 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
  • 2
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

877 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