Hi all,
I read from one directory ( all the files - which contains ipconfig/all) result.
I have written a code which can take Ip host form each file and stored that in array.My problem is , I am getting below result..
But , I would like to have
array
( [0] => .... )
array
([1] => ......)
like this,
My code is
Thanks,
I read from one directory ( all the files - which contains ipconfig/all) result.
I have written a code which can take Ip host form each file and stored that in array.My problem is , I am getting below result..
Code:
Array
(
[0] => ip
hostname
)
Array
(
[0] => ip
hostname
)
Array
(
[0] => ip
hostname
)
array
( [0] => .... )
array
([1] => ......)
like this,
My code is
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))
{
$output = array(); $output[] = $matches[1];
}
if(preg_match('/IP Address. . . . . . . . . . . . : 10.(.*)$/',$lines,$matches))
{
$ad = "10."; $output1 = array();
$matches[1] = $ad.$matches[1]; $output1[] = $matches[1];
}
if(preg_match('/Physical Address. . . . . . . . . :(.*)$/',$lines,$matches))
{
$output2 = array(); $output2[] = $matches[1];
}}
$ar1= each($output) ;
$ar2 = each($output1);
$ar3 = each($output2) ;
$final = $ar1[1].$ar2[1].$ar3[1];
fclose($handle1);
}
$last = array($val);
foreach($last as $val)
{
$val = $final;
print_r($last) ;}
}
}
closedir($handle); } ?>
Comment