parsing text file in php
I have these line in a text file called file.txt.
=====================================
1 ::lfp ::eth1 ::eth0 ::192.168.1.20 ::1 ::48 ::48 ::28 ::32 ::20
1 ::xzone ::eth1 ::eth0 ::192.168.1.21 ::1 ::48 ::48 ::28 ::32 ::21
#1 ::lec ::eth1 ::eth0 ::192.168.1.22 ::1 ::64 ::64 ::32 ::32 ::22
1 ::test ::eth1 ::eth0 ::192.168.1.23 ::1 ::48 ::48 ::32 ::32 ::23
====================================================
I want to parse these file so that only select text can be dislpayed. if there is comment on the line with "#" then that line should be skipped. How can I do that?
Output should be
Name: ipaddress: down: up: id:
lfp 192.168.1.20 48 28 20
zone 192.168.1.21 48 32 21
test 192.168.1.22 48 32 23
I have written this script but it didn't help
<?
$filename = "file.txt";
$fp = fopen("$filename", "r") or die("couldnot open a file");
while (!feof($fp)){
$line = fgets($fp, 1024);
if(preg_match("/^#/", $line) ){
next;
}
$client = split("eth0|eth1|::", $line);
foreach($client as $line)
print "$line<br>";
}
?>
Any help
|