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
Code: Select all
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;
}Code: Select all
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;
}Code: Select all
if (preg_match('/$alone/'.'(.*).(short|full).', $file)){Does someone see what I'm doing wrong and how it should be written?
Thanks in advance!