Hello,
I have a problem reading from files, please help me .
I have a directory named "car". In that directory(car) I have 30 .txt files which are named differently, for example(mercedes.txt, audi.txt), where each .txt file contain just one line with a number, for example (if you open the audi.txt file you will see just this number: 416.38).
With a PHP script I need to open the CAR directory, to read all 30 .txt files(to read the number from each .txt), and after that I must to copy theyr contents(the numbers I have read) into a database table column.
PLEASE PLEASE helppppp !
I started like this but I don't know how to continue:
<?php
$dir=opendir("/car/");
while($file=readdir($dir)){
if ($file!="." and $file!="..") {
print "$file<br>";
$lines = file('$file');
foreach ($lines as $line_num => $line){
print "<font color=red>Line #{$line_num}</font> : " . $line . "<br />\n";
}
}
}
closedir($dir);
?>
It doesn't work. It just shows the .txt files names ...but the next step to show the numbers from files doesn't work (it gives error at foreach loop and show the number from just one file)...
Please tell me someone what to do.
Thank you in advance.