Array , output format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajd335
    New Member
    • Apr 2008
    • 123

    Array , output format

    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..

    Code:
    Array
    (
      
                [0] =>  ip
    hostname
            )
    
    Array
    (
       
                [0] => ip
    hostname
          
    )
    Array
    (
        
                [0] =>  ip 
    hostname
            )
    But , I would like to have
    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); }     ?>
    Thanks,
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Line 29: Change it to: [PHP]array_push($las t, $val);[/PHP]
    And declare $last as an array somewhere before that.

    Comment

    • ajd335
      New Member
      • Apr 2008
      • 123

      #3
      Originally posted by hsriat
      Line 29: Change it to: [PHP]array_push($las t, $val);[/PHP]
      And declare $last as an array somewhere before that.
      hey Hsriat ,
      when I tried that , it gives me
      Code:
      array(
      [0] => info of 1st file
      [1] => info of first file
       )
      array(
      [0] => info of 1st file
      [1] => info of first file
       )
      array(
      [0] => info of 2nd file
      [1] => info of 2nd file
       )
      array(
      [0] => info of 2nd file
      [1] => info of 2nd file
       )
      
      Something like that,
      But , i want to have 
      array(
      [0] => info of 1st file
      [1] => info of 2nd file
      and so on
      )
      Thanks,

      Comment

      Working...