I am working on a PHP replacement of a Perl script that I could never get to talk to PHP. Here's what I'm trying to do:
1) Open up a text file and read it. Done.
2) The text file is fundamentally in three tab-delimited columns where not all columns are populated. I need only the value in column two. In perl, a while loop would work handily. Here's where I am now. My problem is I am only returning the middle entry of the first line, not all lines.
Code:
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
list($name, $port) = preg_split("/\s/", $contents);
echo $port;
I need to rewrite this so that php will have all the values from the second column available as an array or variable.
The return:
[user@host bin]$ php -q var.php
137
I changed the code to:
while ($contents) {
list($name, $port) = preg_split("/\s/", $contents);
echo $port'\n';
}
and my return is a loop of 137, the first entry.
Desired return:
[user@host bin]$php -q var.php
137 138 67 22........
A sample of the text file:
netbios-ns 137
netbios-dgm 138
bootps 67
ssh 22
Any and all help is appreciated.
Best,
monger