EvilZone

Programming and Scripting => Web Oriented Coding => : Code.Illusionist December 13, 2014, 11:26:53 PM

: Is this good way to do it
: Code.Illusionist December 13, 2014, 11:26:53 PM
I know that topic title is kinda bad, but whateva. Anyway, I have one file named test.txt and Inside it I have content like this:

:
Evilzone , http://www.evilzone.org , 789456
Krstarica , http://www.krstarica.com , 789456
Facebook , http://www.facebook.com , 147852
Twitter , http://www.twitter.com , 258963
First one is forum Name, second one is URL and third one is password. Now, my question is, is it good to use this code to print table for HTML:

: (php)
<!doctype html>
<html>
<head>
 
</head>
<body>
<?php
$file "test.txt";
$fContent file_get_contents($file);
$fContent explode("\n",$fContent);
foreach($fContent as $key => $value) {
$tEverything[$key] = explode(",",$value);
}
echo "<table width=600 border=1>";
for($i 0;$i count($tEverything);$i++) {
echo "<tr>";
for($j 0$j 3$j++) {
echo "
<td>
{$tEverything[$i][$j]}</td>";
}
echo "</tr>";
}
echo "</table>";
?>

</body>
</html>

I am curious , is there shorter way to do this, but to print result as I wanted.
: Re: Is this good way to do it
: Schalla December 14, 2014, 12:55:15 AM
: (php)
<?php
$file "test.txt";
$fContent file_get_contents($file);
$fContent explode("\n",$fContent);
?>
     
<!doctype html>
<html>
<head>
<title>title 'n stuff</title>
</head>
<body>
<table width="600" border="1">
<?php foreach($fContent as $row):?>
<tr>
<?php foreach(explode(",",$value) as $value):?>
<td><?=$value?></td>
<?php endforeach;?>
</tr>
<?php endforeach;?>
</table>
</body></html>

Since you asked for a short version, I didnt even split up the explode.

However, never split up logical code (open, calculate, etc) and print. Always separate the sections, that way your
code is more clean.

This version is the shortest code I can imagine at least.
: Re: Is this good way to do it
: s3my0n December 14, 2014, 02:33:50 PM
: (php)
<table>
<?php
if (($fp fopen('test.txt''r'))) {
    while ((
$data fgetcsv($fp))) {
        echo 
'<tr>';
        foreach (
$data as $value)
            echo 
"<td>$value</td>";
        echo 
'</tr>';
    }
    
fclose($fp);
}
?>

</table>
: Re: Is this good way to do it
: Code.Illusionist December 14, 2014, 11:30:10 PM
Thank you both for help.