I have the PHP output, which is in table form, and I want that output in CSV format. How can I get that using PHP Smarty?
A:
You should parse that PHP output with an xml parser. Use somethink like:
$phpOutput = ... ; //this is the output containing only the table
$xml = simplexml_load_string($phpOutput);
$csvOutput = "";
foreach ($xml->tr as $rows)
{
$cells = array();
foreach ($rows->td as $cell)
{
$cells[] = (string)$cell;
}
$csvOutput .= implode(",",$cells)."\r\n";
}
$smarty->assign("csv",$csvOutput);
Of course you must be careful and close every tag if you don't want to get warnings.
Zsolti
2010-08-03 08:02:22
Thanks for your response,but i want to know that whether i can have a link to html o/p i.e export to csv so it can generate that o/p in csv.
chirs
2010-08-03 13:33:50
This is not a problem, you have to access that page with a separate request and before outputing anything add some headers which will force the browser to show you the save file dialog. See more on http://php.net/header
Zsolti
2010-08-04 05:58:21