Solved

Function eregi() is deprecated

Posted on 2014-02-22
2
303 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 108

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 108

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now