Simple PHP Script to read Tab Delimited File


<?php
$filename = "c:\info.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd,filesize ($filename));

fclose ($fd);
$newline = "\n";
$splitcontents = explode($newline, $contents);
$counter = "";
?>
<font color="blue" face="arial" size="4">Complete File Contents</font>
<hr>
<?php
echo $contents;
?>

<br><br>
<font color="blue" face="arial" size="4">Split File Contents</font>
<hr>
<table border="1">
<?php
foreach ( $splitcontents as $color )
{

$counter = $counter+1;
#echo " $color\n<br>";
echo "<tr>";
$delimiter = "/t";
$splitcontents1 = explode($delimiter, $color);

foreach ( $splitcontents1 as $value )
{
if($value == null)
{ echo " "; }
echo "<td> $value </td>";
}
echo "</tr>";
}

?>
</table>

Comments

Anonymous said…
Delimiter in line 32 should be tab not space
$delimiter = '\t';
Gaurav Panchal said…
Thanks for correction

Popular posts from this blog

Switching from Notepad++ FTP to Visual Studio Code FTP

jTable to edit and process MySQL table using CodeIgnitor : Part 2