Php de Çoklu Dosya Arama – php Multi File Search

Php de Çoklu Dosya Arama – php Multi File Search

<?php
class file_search
{
var $found = array();

function file_search($files, $dirs = ‘.’, $sub = 1, $case = 0)
{
$dirs = (!is_array($dirs)) ? array($dirs) : $dirs;
foreach ($dirs as $dir)
{
$dir .= (!ereg(‘/$’, $dir)) ? ‘/’ : ”;
$directory = @opendir($dir);

while (($file = @readdir($directory)) !== FALSE)
{
if ($file != ‘.’ && $file != ‘..’)
{
if ($sub && is_dir($dir . $file))
{
$this->file_search($files, $dir . $file, $sub, $case);
}
else
{
$files = (!is_array($files)) ? array($files) : $files;
foreach ($files as $target)
{
$tar_ext = substr(strrchr($target, ‘.’), 1);
$tar_name = substr($target, 0, strrpos($target, ‘.’));
$fil_ext = substr(strrchr($file, ‘.’), 1);
$fil_name = substr($file, 0, strrpos($file, ‘.’));

$ereg = ($case) ? ‘ereg’ : ‘eregi’;
if ($ereg($tar_name, $fil_name) && eregi($tar_ext, $fil_ext))
{
$this->found[] = $dir . $file;
}
}
}
}
}
}
}
}

$find = array(‘test.[^php]’, ‘contact.php|html’);
$search = new file_search($find);

echo ‘<pre>’;
print_r($search->found);
echo ‘</pre>’;
?>

Bana Ders Anlat © 2008-2022