Jan 6, 2018 12:05 PM
(This post was last modified: Jan 6, 2018 12:11 PM by milknpepper.)
Been stuck on this for over 2 hours - pls assist:
End goal: To turn contents of every txt file in my directory into a table.
So I have .txt files with contents like:
Giraffe: 1
Banana: 2
Monkey: 3
From each txt file I want it take out the "1" "2" and "3" and put it into columns (so I can later just paste it into excel and its already splitted).
I was able to achieve this for ONE file at a time using the script below:
That is for alskdgj.txt, works perfect. But is it possible to do a forreach argument in the script so that it scans the directory and does this function for EVERY txt file in that directory ?
So that if I have 5 files, it would eventually give me a table with the values from the 5 txt files - rather doing each one by one.
Plz help. 🤝
End goal: To turn contents of every txt file in my directory into a table.
So I have .txt files with contents like:
Giraffe: 1
Banana: 2
Monkey: 3
From each txt file I want it take out the "1" "2" and "3" and put it into columns (so I can later just paste it into excel and its already splitted).
I was able to achieve this for ONE file at a time using the script below:
PHP Code
<?php
<body>
<?php
$lines = file('alskdgj.txt'); //here's the filename
?>
<table width=800>
<?php
foreach ($lines as $line) {
list($a,$b) = explode(':', $line);
print "<td width=40>$b</td>";
}
?>
</table>
</body>
That is for alskdgj.txt, works perfect. But is it possible to do a forreach argument in the script so that it scans the directory and does this function for EVERY txt file in that directory ?
So that if I have 5 files, it would eventually give me a table with the values from the 5 txt files - rather doing each one by one.
Plz help. 🤝


