Create table from text file using PHP -
i need create table borders text file (this text file updated every time when finishes filling form. 1 row, 1 person):
herard|tro789|suzuki|france|gendolfina|fresko|food|500|2015-04-25 14:40 bob|mga789|mercedes|latvia|polaris|dread|parts|1000|2015-04-26 16:15
i've created script reads every word separately, don't know how to put them table:
<?php $file = fopen("info.txt", "r") or die("unable open file!"); while (!feof($file)){ $data = fgets($file); list($name, $number, $type, $country, $company, $gcompany, $supply, $weight, $datetime) = explode("|", $data); } fclose($failas); ?>
so need script read text file , create table same number of rows text file has.
use str_replace
replace |
signs html table cell delimiters.
<?php echo '<table border="1">'; $file = fopen("info.txt", "r") or die("unable open file!"); while (!feof($file)){ $data = fgets($file); echo "<tr><td>" . str_replace('|','</td><td>',$data) . '</td></tr>'; } echo '</table>'; fclose($file); ?>
Comments
Post a Comment