.sif file generator in Laravel

23 Views Asked by At

I am working on my project is there any formatter in Laravel to convert data to .sif format. I know DomPDF is used for pdf format. Or can I do it in any other way?


$htmlContent = "\<tr\>\<td\>John_1\</td\>\<td\>10,000\</td\>\</tr\>
\<tr\>\<td\>John_2\</td\>\<td\>15,0000\</td\>\</tr\>
\<tr\>\<td\>John_3\</td\>\<td\>10,00\</td\>\</tr\>
\<tr\>\<td\>John_4\</td\>\<td\>13,000\</td\>\</tr\>
\<tr\>\<td\>John_5\</td\>\<td\>50\</td\>\</tr\>
\<tr\>\<td\>John_6\</td\>\<td\>21,000\</td\>\</tr\>"

$dom = new DOyour textMDocument();
$dom-\>loadHTML($htmlContent);
$table = $dom-\>getElementsByTagName('table')-\>item(0);
$rows = $table-\>getElementsByTagName('tr');
$sif = array();

           for ($i = 1; $i < $rows->length; $i++) {
               $row = $rows->item($i);
               $cells = $row->getElementsByTagName('td');
               $source = $cells->item(0)->nodeValue;
               $target = $cells->item(1)->nodeValue;
               $type = 'email';
               $sif_line = $source . " " . $type . " " . $target;
               $sif[] = $sif_line;
           }
    
           $sif_content = implode("\n", $sif);
    
           // echo $sif;
           $headers = [
               'Content-Type' => 'text/plain',
               'Content-Disposition' => 'attachment; filename=example.sif',
           ];
           return response($sif_content,200,$headers);


I tried to create a .sif format file it is correct way? Any library or package there available to format?

0

There are 0 best solutions below