Zipa sad rafo :D
Radi mi onaj tvoj kod sa scandir, ali ovaj moj stari koji na windowsu radi ovde ne radi, tacnije ne udje uopste u drugu foreach petlju, stavio sam tu echo "test" radi testa i tacno se to ne pojavi.
Meni treba da izvuce iz sadrzaja fajla odredjeni regexp, a ne samo imena fajla da izlista.
edit: file($filename) mi vraca prayan rezultat, a kad ehujem $filename to je regularno ime fajla sa celom putanjom
Evo koda
Code:
<?php
//setup php for working with Unicode data
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
header('Content-Type: text/html; charset=utf-8');
setlocale(LC_ALL, 'sr_RS.UTF-8@latin', 'sr_RS.UTF-8@Latn', 'sr_CS.UTF-8@Latn');
// the following line prevents the browser from parsing this as HTML.
//header('Content-Type: text/plain; charset=utf-8');
$path_to_check = "/var/www/html/NOC/Sessions/";
$hostname = 'Hostname'; $protocol = '"Protocol Name"'; $current = ''; $file = 'sessions.ini';
$matchesHost[1]=$matchesIP[1]=$matchesProtocol[1]='';
foreach(glob($path_to_check.'*.ini') as $filename)
{ echo $filename;
foreach(file($filename) as $fli=>$fl)
{ echo "test";
if(mb_strpos($fl, $hostname, 0, 'UTF-8')!==false)
{
$result = $filename.' on line '.($fli+1).': '.$fl;
echo $result; echo "<br />";
preg_match("/Sessions\/(.*?)\b.ini\b/", $result, $matchesHost);
preg_match("/Hostname\"=(.*?)$/", $result, $matchesIP);
$matchesHost[1] = trim($matchesHost[1]); $matchesIP[1] = trim($matchesIP[1]);
$current .= $matchesHost[1] . "##" . $matchesIP[1] ."\n";
file_put_contents($file, $current);
}
if(mb_strpos($fl, $protocol)!==false)
{
$result = $filename.' on line '.($fli+1).': '.$fl;
echo $result;echo "<br />";
preg_match("/\"Protocol Name\"=(.*?)$/", $result, $matchesProtocol);
$matchesProtocol[1] = trim($matchesProtocol[1]);
//$current = file_get_contents($file);
$current .= $matchesProtocol[1] . "#";
file_put_contents($file, $current);
}
}
}
?>
[Ovu poruku je menjao geenije dana 18.11.2014. u 18:13 GMT+1]