I'd like to take a CSV file living server-side and display it dynamically as an html table. E.g., this:
Name, Age, Sex
"Cantor, Georg", 163, M
should become this:
<html><body><table>
<tr> <td>Name</td> <td>Age</td> <td>Sex</td> </tr>
<tr> <td>Cantor, Georg</td> <td>163</td> <td>M</td> </td>
</table></body></html>
Solutions in any language are welcome.
The previously linked solution is a horrible piece of code; nearly every line contains a bug. Use fgetcsv instead:
Here is a simple function to convert csv to html table using php:
One can call this function like
jj_readcsv('image_links.csv',true);
if second parameter is true then the first row of csv will be taken as header/title.
Hope this helps somebody. Please comment for any flaws in this code.
XmlGrid.net has tool to convert csv to html table. Here is the link: http://xmlgrid.net/csvToHtml.html
I used your sample data, and got the following html table:
HTML ... tag can do that itself i.e. no PHP or java.
or see this post for complete detail on the above (with all options..).
http://www.linuxquestions.org/questions/programming-9/how-to-show-csv-data-as-html-in-internet-explorer-with-filter-buttons-4175443612/
phihag's answer puts each row in a single cell, while you are asking for each value to be in a separate cell. This seems to do it:
define "display it dynamically" ? that implies the table is being built via javascript and some sort of Ajax-y update .. if you just want to build the table using PHP that's really not what I would call 'dynamic'