I want to generate CSV File from HTML table which contains logo image and other invoice data
in $content
i have invoice html data in table format. I have tried this displaying with
$csv = array();
preg_match('/<table(>| [^>]*>)(.*?)<\/table( |>)/is',$content,$b);
$table = $b[2];
preg_match_all('/<tr(>| [^>]*>)(.*?)<\/tr( |>)/is',$content,$b);
$rows = $b[2];
foreach ($rows as $row) {
//cycle through each row
if(preg_match('/<th(>| [^>]*>)(.*?)<\/th( |>)/is',$row)) {
//match for table headers
preg_match_all('/<th(>| [^>]*>)(.*?)<\/th( |>)/is',$row,$b);
$csv[] = strip_tags(implode(',',$b[2]));
} elseif(preg_match('/<td(>| [^>]*>)(.*?)<\/td( |>)/is',$row)) {
//match for table cells
preg_match_all('/<td(>| [^>]*>)(.*?)<\/td( |>)/is',$row,$b);
$csv[] = strip_tags(implode(',',$b[2]));
}
}
$csv = implode("\n", $csv);
$furl="C:\WTServer\WWW/test.txt";
file_put_contents($furl,$csv);