i am trying to convert pdf file to excel. So first i have fetched the data from pdf and adding that to excel when i have hard-coded the values then it is working file but i want code without hard-coding my code is:-
$result = pdf2text ('1.pdf');
$array1 = explode('***', $result );
function filterData(&$str) {
$str = preg_replace("/\t/", "\t", $str); $str = preg_replace("/\r? \n/", "\n", $str);
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; }
$data = array(
array($array1[0]),
array($array1[1]),
array($array1[2])
);
$fileName = "codexworld_export_data" . date('Ymd') . ".xls";
// headers for download
header("Content-Disposition: attachment; filename=\"$fileName\"");
header("Content-Type: application/vnd.ms-excel");
foreach($data as $row) {
array_walk($row, 'filterData');
echo implode("\t", array_values($row)) . "\n";
}
exit;
above code is working fine but i don't want to mention array1 as $array1[0],$array1[1],$array1[2].
because my pdf file may have multiple values also so please tell me how to assign $array1 to $data
Try Like this..
$array1 =array('aaa',22);//an assumed array
foreach ($array1 as $key=>$value)
{
$data[] = array($value);
}
print_r($data);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.