PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Jul 17, 2019 8:42 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Nov 27, 2011 3:59 pm 
Offline
Forum Newbie

Joined: Sun Nov 27, 2011 3:49 pm
Posts: 2
Location: Croatia
Hello.

I'm having a problem with changing a function which uses eregi() into a preg_match() to gain compatiblity with PHP 5.3 .
Here is the orginal function with eregi
Syntax: [ Download ] [ Hide ]
function cache_remover($alone = ''){

        $fdir = opendir(rootpath.'/cache');
        while ($file = readdir($fdir)){
                if ($file != '.' and $file != '..' and $file != '.htaccess'){
                        if ($alone){
                                if (eregi($alone.'(.*).(short|full).', $file)){
                                        @unlink(rootpath.'/cache/'.$file);
                                }

                                if (!eregi('.(short|full).', $file)){
                                        @unlink(rootpath.'/cache/'.$file);
                                }
                        }

                        if (!$alone){
                                @unlink(rootpath.'/cache/'.$file);
                        }
                }
        }

return true;
}


I have modified the function into this:
Syntax: [ Download ] [ Hide ]
function cache_remover($alone = ''){

        $fdir = opendir(rootpath.'/cache');
        while ($file = readdir($fdir)){
                if ($file != '.' and $file != '..' and $file != '.htaccess'){
                        if ($alone){
                                if (preg_match('/$alone/'.'(.*).(short|full).', $file)){
                                @unlink(rootpath.'/cache/'.$file);
                                }
                                // if (!preg_match('/(short|full)/', $file)){
                                if (!preg_match('.(short|full).', $file)){
                                        @unlink(rootpath.'/cache/'.$file);
                                }
                        }
                        if (!$alone){
                        @unlink(rootpath.'/cache/'.$file);
                        }
                }
        }
       
        return true;
}


however, I'm getting an error Warning: preg_match() [function.preg-match]: Unknown modifier '(' in ... on line
Syntax: [ Download ] [ Hide ]
if (preg_match('/$alone/'.'(.*).(short|full).', $file)){
.

Does someone see what I'm doing wrong and how it should be written?

Thanks in advance!


Top
 Profile  
 
PostPosted: Sun Nov 27, 2011 7:34 pm 
Offline
DevNet Resident
User avatar

Joined: Wed Apr 01, 2009 1:31 pm
Posts: 1532
Try these.
Syntax: [ Download ] [ Hide ]
if (preg_match('/'.$alone.'(.*).(short|full)./', $file)){
Syntax: [ Download ] [ Hide ]
if (!preg_match('/.(short|full)./', $file)){


Top
 Profile  
 
PostPosted: Mon Nov 28, 2011 2:40 pm 
Offline
Forum Newbie

Joined: Sun Nov 27, 2011 3:49 pm
Posts: 2
Location: Croatia
Hi McInfo!
Your suggestion solved the problem. No errors, everything works good now.
Thanks alot!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group