PHP code example of digitaldream / data-converter

1. Go to this page and download the library: Download digitaldream/data-converter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

digitaldream / data-converter example snippets


$fileManager = new \DataConverter\FileExcel();


  $config = [
    'file_path' => 'C:\Users\Tuhin\Downloads\apiv1567623ccbcfc1_570a009e10650.xlsx',    
    'first_row_as_headline' => true,    
  ];

  $data = $fileManager->config($config)->read()->getData();   
  //$data = $fileManager->config($config)->read()->toJson();  
  //$data = $fileManager->config($config)->read()->toText();  
  //$data = $fileManager->config($config)->read()->toAssoc(); 
  print_r($data);  
  


//Here it will process the file based on file mimetype. 

$fileFullPath='test.txt';

  $fileManager = \DataConverter\FileManager::initByFileType($fileFullPath);

if ($fileManager === FALSE) {
 // exit() File tye does not mathch 
 }
 
 //here we used filter. It will take only these two columns value and other data from the souce will be ignored.
 
 $data = $fileManager->config($config)->read()->makeAssoc()->filter(['column_1','column_2])->getData();


 $fileManager = new \DataConverter\FileExcel();
 $configFile = [ 
     'file_path' => $fullPath,// full file path where file will be saved.     
       'data' => $data,//data as associative array.       
       'mode' => 'w+'//only valid if file type is txt       
    ];
  $fileManager = $fileManager->config($configFile)->filter(['column 1','column 2'])->write(true);