Import .CSV file and convert it to HTML table view

By using the following PHP code you can import CSV / Excel CSV and you can create it by yourself or export from any table using phpMyAdmin and finally convert this data to array for viewing HTML table or you can use this data array as input for programming purpose.

Here is the code

* Import .CSV file and convert it to HTML table view
* @author Md. Nazmul Basher (
* @Web
* @Mobile +8801712994064
<form action=”<?php echo $_SERVER[‘PHP_SELF’];?>” method=”post” enctype=”multipart/form-data” name=”import”>
<label for=”input_import_file”>Location of the CSV file:</label>
<input name=”import_csvfile” id=”import_csvfile” type=”file”>
<input name=”csvsubmit” id=”csvsubmit” value=”Go” type=”submit”>
echo ‘<table width=”100%” border=”1″ cellspacing=”5″ cellpadding=”0″ bordercolor=”#CCCCCC” style=”border-collapse:collapse;”>’;
$handle = fopen($_FILES[‘import_csvfile’][‘tmp_name’], “r”);
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {
$num = count($data);
echo “<tr>”;
for ($c=0; $c < $num; $c++) {
echo “<td>&nbsp;”.$data[$c].”</td>”.”\n”;
echo “</tr>”;
echo “</table>”;

And here is an example .csv file for import:

Pls click to download

After download just unzip the file to get .csv file inside it.



One Response to Import .CSV file and convert it to HTML table view

  1. KoLLoL says:

    Thanks for the information. I am sure this is going to help a lot of beginners. 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: