Simple PHP Script to read Tab Delimited File

Monday, March 25, 2013

<?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>

5 comments:

Anonymous said...

Delimiter in line 32 should be tab not space
$delimiter = '\t';

Gaurav Panchal said...

Thanks for correction

E- learning Docker kubernetes said...

This is really an amazing post, thanks for sharing such a valuable information with us, keep sharing!!
Docker Online Training
Kubernetes Online Training
Kubernetes Training in Hyderabad
Docker and Kubernetes Training in Hyderabad

infocampusbangalore said...

Nice post. I learn something totally new and challenging on websites I come across on a daily basis. It will always be helpful to read through articles from other writers and use a little something from other websites.
UI Development Training in Bangalore
Reactjs Training in Bangalore

Anonymous said...

Nice post

https://www.santanu.biz