Zen Cart Logo
Forums / Code Collaboration / ereg to preg_match?

ereg to preg_match?

Views: 1,379

Results 1 to 4 of 4
31 Jan 2018, 8:38 PM
#1
tmccaff avatar

tmccaff

Zen Follower

Join Date:
Jan 2018
Posts:
157
Plugin Contributions:
0

ereg to preg_match?

I have an old plugin that I am updating and I see ereg which was replaced by preg_match in php7.

Here is the code:

if ( (!isset($_GET['sort'])) || (!ereg('[1-9][ad]', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($define_list)) ) {

Would it be changed to?

if ( (!isset($_GET['sort'])) || (!preg_match('/[1-9][ad]', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($define_list)) ) {
31 Jan 2018, 8:48 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: ereg to preg_match?

Close! You'll want to add the ending delimiter, too:

if ( (!isset($_GET['sort'])) || (!preg_match('/[1-9][ad][B]/[/B]', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($define_list)) ) {  
31 Jan 2018, 8:48 PM
#3
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: ereg to preg_match?

you are missing a slash

if ( (!isset($_GET['sort'])) || (!preg_match('/[1-9][ad]', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($define_list)) ) { 

should be

if ( (!isset($_GET['sort'])) || (!preg_match('/[1-9][ad]/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($define_list)) ) { 
4 Feb 2018, 6:18 PM
#4
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,763
Plugin Contributions:
9

Re: ereg to preg_match?

Great minds think alike:P By the timestamp, I note a virtual tie. We may need to go to the tape for the winner on this one.:laugh: