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.. -
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 -
<?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,
2 1877
Line 29: Change it to: [PHP]array_push($last, $val);[/PHP]
And declare $last as an array somewhere before that.
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 -
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,
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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;
|
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...
|
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...
|
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>...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| | |