Use:
Where it printed "array()" 10 times means that you have 10 files in that directory but you never matched anything from your preg_match().
Just for fun, replace print_r($matches) with var_dump($lines) and tell me what you get? Not sure if that gives you line by line or the whole file. Also, you may need a 'g' pattern modifier to turn on global pattern searching.
Hi Bretticus ,
It was a small mistake why the answer was not showing up...
I have the below code
-
<?php
-
$dirname = "/home/ajd/ip";
-
if($handle = opendir($dirname))
-
{
-
while(false !== ($filename = readdir($handle))){
-
if (is_readable($filename)) {
-
if ($handle1 = fopen($filename, "r") ) {
-
while(!feof($handle1)) {
-
$lines = fgets($handle1);
-
if(preg_match('/ Host Name . . . . . . . . . . . . :(.*)$/',$lines,$matches))
-
{
-
print_r($matches[1]);
-
echo ",";
-
}
-
-
-
if(preg_match('/IP Address. . . . . . . . . . . . : 10.(.*)$/',$lines,$matches))
-
{ $ad = "10.";
-
print_r($ad.$matches[1]);
-
}
-
if(preg_match('/Physical Address. . . . . . . . . :(.*)$/',$lines,$matches))
-
{
-
print_r($matches[1]);
-
echo ",";
-
-
}
-
} fclose($handle1);
-
} } }
-
-
closedir($handle);
-
}
-
?>
-
and the result I get is file1hosname,file1physicaladd,file1'sIp,file2'shos tname.........
Now actually , I want to store the result into one text file or execel file.(or database)...I need a way in which i can store the value of (e.g)
array1[0] = file1's hostname
array1[1]= file2's hostname
....
array2[0] = file1's IP
array2[1]= file2's Ip ....
how can i do so...?
Thanks