forse così?
Codice PHP:
$files=list_elements('dati','files');
foreach($files as $file)
{
$blocks=explode('.',$file)
$ext = array_pop($blocks);
if ($ext =='html')
{
$code = file_get_contents($file);
$titolo = '';
$descrizione = '';
if(preg_match('@<title>([^<]*?)</title>@', $code, $match)){
$titolo = $match[1];
}
if(preg_match('@<meta name="description" content="([^"]*?)">@', $code, $match)){
$descrizione = $match[1];
}
echo "$file : $titolo , $descrizione
";
}
}
function list_elements($dir,$out)
{
$file_list = '';
$stack[] = $dir;
while ($stack)
{
$current_dir = array_pop($stack);
if ($dh = opendir($current_dir))
{
while (($file = readdir($dh)) !== false)
{
if ($file !== '.' AND $file !== '..')
{
$current_file = "{$current_dir}/{$file}";
if (is_file($current_file))
{
$file_list[] = "{$current_dir}/{$file}";
}
elseif (is_dir($current_file))
{
$stack[] = $current_file;
$dirs[]=$current_file;
}
}
}
}
}
if ($out=='file') return $file_list;
elseif ($out=='dir' ) return $dirs;
}