Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 3.145.64.210
<?php
//$filename = 'subjects.csv';
include "simplehtmldom/simple_html_dom.php";
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$table = $_POST['Export'];
$html = str_get_html(trim($table));
//$columnHeader = '';
//$columnHeader = "Degree Code" . "\t" . "Degree Name" . "\t";
// header("Content-Description: File Transfer");
// header("Content-Disposition: attachment; filename=".$filename);
// header("Content-Type: application/csv; ");
// //$setData = '';
// // file creation
// $file = fopen($filename,"w");
// foreach ($export_data as $line){
// var_dump('aaaaa');
// var_dump($line);
// fputcsv($file,$line);
// }
// die();
// fclose($file);
// // download
// //echo ucwords($columnHeader)."\n". "\n";
// readfile($filename);
// // deleting file
// unlink($filename);
// exit();
$fileName="subjects.csv";
header('Content-type: application/ms-excel');
header("Content-Disposition: attachment; filename=$fileName");
$fp = fopen("php://output", "w");
$csvString="";
foreach($html->find('tr') as $element)
{
$td = array();
foreach( $element->find('th') as $row)
{
$row->plaintext="\"$row->plaintext\"";
$td [] = $row->plaintext;
}
$td=array_filter($td);
$csvString.=implode(",", $td);
//fputcsv($fp, $td);
$td = array();
foreach( $element->find('td') as $row)
{
$row->plaintext="\"$row->plaintext\"";
$td [] = $row->plaintext;
}
$td=array_filter($td);
$csvString.=implode(",", $td)."\n";
}
echo $csvString;
fclose($fp);
exit;
?>
|