473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Array , output format

123 100+
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..

Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.  
  4.             [0] =>  ip
  5. hostname
  6.         )
  7.  
  8. Array
  9. (
  10.  
  11.             [0] => ip
  12. hostname
  13.  
  14. )
  15. Array
  16. (
  17.  
  18.             [0] =>  ip 
  19. hostname
  20.         )
  21.  
But , I would like to have
array
( [0] => .... )
array
([1] => ......)
like this,
My code is
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  $dirname = "/home/ajd/ip";
  3. if($handle = opendir($dirname))
  4. {
  5.     while(false !== ($filename = readdir($handle))){
  6.         if (is_readable($filename)) {
  7.   if ($handle1 = fopen($filename, "r") ) {
  8.                 while(!feof($handle1)) {
  9.                     $lines = fgets($handle1);
  10. if(preg_match('/ Host Name . . . . . . . . . . . . :(.*)$/',$lines,$matches))
  11.  {
  12. $output = array();  $output[] = $matches[1];
  13. }
  14. if(preg_match('/IP Address. . . . . . . . . . . . : 10.(.*)$/',$lines,$matches))
  15. {
  16. $ad = "10."; $output1 = array();
  17.   $matches[1] = $ad.$matches[1];   $output1[] = $matches[1]; 
  18. }
  19. if(preg_match('/Physical Address. . . . . . . . . :(.*)$/',$lines,$matches))
  20.  {
  21. $output2 = array();    $output2[] = $matches[1];
  22. }}
  23.  $ar1= each($output) ;  
  24. $ar2 = each($output1);  
  25. $ar3 = each($output2) ;
  26. $final = $ar1[1].$ar2[1].$ar3[1];
  27. fclose($handle1);
  28. }
  29. $last = array($val);
  30. foreach($last as $val)
  31. $val = $final;
  32.  print_r($last) ;}
  33.  
  34.   }
  35.     }
  36.     closedir($handle); }     ?>
  37.  
Thanks,
Jul 14 '08 #1
2 1877
hsriat
1,654 Expert 1GB
Line 29: Change it to: [PHP]array_push($last, $val);[/PHP]
And declare $last as an array somewhere before that.
Jul 14 '08 #2
ajd335
123 100+
Line 29: Change it to: [PHP]array_push($last, $val);[/PHP]
And declare $last as an array somewhere before that.
hey Hsriat ,
when I tried that , it gives me
Expand|Select|Wrap|Line Numbers
  1. array(
  2. [0] => info of 1st file
  3. [1] => info of first file
  4.  )
  5. array(
  6. [0] => info of 1st file
  7. [1] => info of first file
  8.  )
  9. array(
  10. [0] => info of 2nd file
  11. [1] => info of 2nd file
  12.  )
  13. array(
  14. [0] => info of 2nd file
  15. [1] => info of 2nd file
  16.  )
  17.  
  18. Something like that,
  19. But , i want to have 
  20. array(
  21. [0] => info of 1st file
  22. [1] => info of 2nd file
  23. and so on
  24. )
  25.  
Thanks,
Jul 14 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jan Killian | last post by:
Hi all, maybe you'll see the trick and could help me. I am passing int by reference and get an exception when using it as an index to passed array. (Yes I know I can workaround with object...
2
by: Knoxy | last post by:
Hi there, Hope someone can help. I've had a look around on the web and found some useful info but not getting this to work... seen lots of different variations PROBLEM: ======== I have a...
4
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it...
29
by: yourmycaffiene | last post by:
Okay, this if my first post so go easy on me plus I've only been using C for a couple of weeks. I'm working on a program currently that requires me to read data from a .dat file into a 2d array and...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
29
by: foker | last post by:
I have this problem where I have 2 text files, one with student name, id#, # of courses and course #, the second file has course name and course number. I want to make a multidimensional array that...
1
by: phjones | last post by:
This is not a class project.The program below is to display mortgage interest paid for each payment over the term of the loan and loan balance.It is program using array. However, I am receiving the...
15
by: bernd | last post by:
Hi folks, a simple question for the experts, I guess. Obviously I am doing something wrong when trying to access an element of an array declared within a structure: #include <stdio.h>...
5
by: Lawrence Krubner | last post by:
I'm suppose to track FTP uploads to the server. I've got a cron script, written in PHP, that runs every 5 minutes and which does the command lsof | grep vsftpd This gives me a big file that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.