Jump to content

Problem with !eregi


Powerz

Recommended Posts

Hello.I got some error in my code:

Deprecated: Function eregi() is deprecated in config.php on line 84

 

This is my code

 

if(!eregi( "^[a-zA-Z\-_0-9/-]+$", $type )) unset($type);

if(!eregi( "^[a-zA-Z\-_0-9/]+$", $act )) unset($act);

if(!eregi( "^[a-zA-Z\-_0-9/]+$", $id )) unset($id);

 

Can someone help me what should be changed  :shrug:

 

 

Link to comment
https://forums.phpfreaks.com/topic/257636-problem-with-eregi/
Share on other sites

Yes, the function has been deprecated as of PHP version 5.3.0

you can use preg_match instead.

 

if(!preg_match( "~^[-a-zA-Z_0-9/]+$~i", $type )) unset($type);
if(!preg_match( "~^[a-zA-Z\-_0-9/]+$~i", $act )) unset($act);
if(!preg_match( "~^[a-zA-Z\-_0-9/]+$~i", $id )) unset($id);

Link to comment
https://forums.phpfreaks.com/topic/257636-problem-with-eregi/#findComment-1320474
Share on other sites

If I am understanding that expression correctly you could simplify that as

preg_match( "~^[\w-/]+$~", $value )

 

yes, another way of writing it, except that you want to keep the dash immediately following the opening character class bracket so it is not treated as a meta-character. Also, the OP was using eregi(), which performs a case-insensitive search, thus the reason for the appended "i" modifier.

Link to comment
https://forums.phpfreaks.com/topic/257636-problem-with-eregi/#findComment-1320479
Share on other sites

If I am understanding that expression correctly you could simplify that as

preg_match( "~^[\w-/]+$~", $value )

 

yes, another way of writing it, except that you want to keep the dash immediately following the opening character class bracket so it is not treated as a meta-character. Also, the OP was using eregi(), which performs a case-insensitive search, thus the reason for the appended "i" modifier.

 

Right, but doesn't the use of \w remove the need to use 'i' for case insensitivity?

Link to comment
https://forums.phpfreaks.com/topic/257636-problem-with-eregi/#findComment-1320490
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.