0

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

1 Answer 1

1

Try Like this..

 $array1 =array('aaa',22);//an assumed array
    foreach ($array1 as $key=>$value)
    {
     $data[] = array($value);    
    }
    print_r($data);
Sign up to request clarification or add additional context in comments.

4 Comments

I am having only values in array ie $array1[0] = x, $array1[1] = y, $array1[2] = z so iam using $data = array($array1);
like this... $data = array(array_values($array1)); same as above.
data is entering horizantally(only in columns) but i want vertically(only in rows) ie in excel data has entered in A,B,C columns, But i want the data has to be entered only in A column(A1,A2,A3)
echo implode("\n", array_values($row)) . "\n"; inside foreach()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.