Solved

Function eregi() is deprecated

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

752 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