ISSUE :
 
Profile photo
Submitted by Robert Legoo
on June 8th, 2011 at 02:52:53 EST

Preg_match - Delimeter issue

Hello

I've managed to convert most of my script to PHP 5.3. Some examples of what I changed are below:

----------------------------------------------------------------------
FIND => if (eregi('.', $mstr)) {

REPLACE WITH => if (preg_match('/./i', $mstr)) {
----------------------------------------------------------------------
FIND => if(eregi('.php', $ref)) { $ref=false; }

REPLACE WITH => if(preg_match('/.php/i', $ref)) { $ref=false; }
----------------------------------------------------------------------
FIND => $result = mysql_query("SELECT * FROM users WHERE lastaction >= unix_timestamp() - 60*5 AND `username` != 'winnerbux' AND `hidestatus`='0'");

REPLACE WITH => $result = mysql_query("SELECT * FROM users WHERE lastaction >= unix_timestamp() - 60*5 AND `hidestatus`='0'");
----------------------------------------------------------------------
FIND => if(eregi("-".$qa['aId']."-", $ir['ads_clicked'])) $clicked = "image2";

REPLACE WITH => if(preg_match('/-i/'.$qa['aId'].'/-i/', $ir['ads_clicked'])) $clicked = 'image2';
----------------------------------------------------------------------
FIND => if(eregi('ALL', $r['aCountries']) || eregi($ir['country'], $r['aCountries'])) {

REPLACE WITH => if(preg_match('/ALL/i', $r['aCountries']) || preg_match($ir['country'], $r['aCountries'])) {
----------------------------------------------------------------------
FIND => if(eregi('-'.$r['aId'].'-', $ir['ads_clicked'])) {

REPLACE WITH => if(preg_match('-'.$r['aId'].'-', $ir['ads_clicked'])) {
----------------------------------------------------------------------
FIND => if(eregi('ALL', $r['aCountries']) || eregi($ir['country'], $r['aCountries'])) {

REPLACE WITH => if(preg_match('/ALL/i', $r['aCountries']) || preg_match($ir['country'], $r['aCountries'])) {
----------------------------------------------------------------------
FIND => return @eregi_replace("([*])|([|])|([;]|([`])","",$string);

REPLACE WITH => return preg_replace('/([\.*])|([\|])|([^;"])|([\`])/i',"",$string);
----------------------------------------------------------------------
FIND => if(eregi('.php', $ref)) { $ref=false; }

REPLACE WITH => if(preg_match('/.php/i', $ref)) { $ref=false; }
----------------------------------------------------------------------
FIND => return @eregi_replace("([*])|([|])|([;]|([`])","",$string);

REPLACE WITH => return preg_replace('/([\.*])|([\|])|([^;"])|([\`])/i',"",$string);
----------------------------------------------------------------------


[b][u]There are two codes I'm having issues with:[/b][/u]

FIND => if((eregi('ALL', $qa['aCountries']) || eregi($country, $adcountry)) && $qa['aClicksLeft'.$counter] > 0) {

REPLACE WITH => if((preg_match('/ALL/i', $qa['aCountries']) || preg_match($country, $adcountry)) && $qa['aClicksLeft'.$counter] > 0) {


This spits: Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash. The second eregi is what is causing the issue due to I'm building this in a 5.2 PHP environment and when leaving the second eregi it does not have any issues.

[b][u]The next one is the same error: [/b][/u]

FIND => if($file == "js" or $file == "logout" or $file == "footer" or $file == "header" or $file == "index" or (eregi($scriptname,$ar['aPermissions']) or eregi('ALL', $ar['aPermissions'])))

REPLACE WITH => if($file == "js" or $file == "logout" or $file == "footer" or $file == "header" or $file == "index" or (preg_match($scriptname,$ar['aPermissions']) or preg_match('/ALL/i',$ar['aPermissions'])))


This spits: Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash. Also, has to do with the secon eregi code, as replacing only the first one, causes no errors.

Thanks
Robert


Profile photo
Replied by RaKumar
on June 8th, 2011 at 10:07:04 EST
I think your both first and second issues are similar.
In your first issue, you have something like this:
preg_match($country, $adcountry)
I am not sure what you have stored in the pattern variable $country. but when you use preg_match() in php your pattern parameter should be enclosed within forward slash "/".
For example, preg_match("/abc/", "test abc"); -> this will work great !
You will get Delimeter error if you don't have forward slashes "/". For example, preg_match("abc", "test abc"); will generate error.
However, it use to work with eregi(). With eregi(), eregi("abc", "test abc") works just fine.

So, check if you have your regular expression pattern enclosed within forward slashes "/" in your variable $country.
If not, you can do something simple like
preg_match("/".$country."/", $adcountry)
Accepted Answer
Accepted
 Answer

Profile photo
Replied by Robert Legoo
on June 8th, 2011 at 11:43:20 EST
Hello RaKumar

Thank you for your answer. Below is what solved this, and it is thanks to you :) As you can see, I only changed (compared to my above changes) the one suggestion you made with "/". CODING ."/".

Again, thanks, ... as you can see I managed to change most of it without issue, but those two were really stumping me.

CHANGED:
--------

if($file == "js" or $file == "logout" or $file == "footer" or $file == "header" or $file == "index" or (eregi($scriptname,$ar['aPermissions']) or eregi('ALL', $ar['aPermissions'])))


TO:
--------

if((preg_match('/ALL/i', $qa['aCountries']) || preg_match("/".$country."/", $adcountry)) && $qa['aClicksLeft'.$counter] > 0) {


CHANGED:
--------

if($file == "js" or $file == "logout" or $file == "footer" or $file == "header" or $file == "index" or (eregi($scriptname,$ar['aPermissions']) or eregi('ALL', $ar['aPermissions'])))


TO:
--------

if($file == "js" or $file == "logout" or $file == "footer" or $file == "header" or $file == "index" or (preg_match("/".$scriptname."/",$ar['aPermissions']) or preg_match('/ALL/i',$ar['aPermissions'])))