PHP code example of fiedsch / datamanagement

1. Go to this page and download the library: Download fiedsch/datamanagement 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/ */

    

fiedsch / datamanagement example snippets




iedsch\Data\File\CsvReader;
 
try {
 
  $reader = new CsvReader("testdata.csv", ";");

  // Read and handle all lines containing data.

  while (($line = $reader->getLine()) !== null) {
    // ignore empty lines (i.e. lines containing no data)
    if (!$reader->isEmpty($line)) {
      print_r($line);
    }
  }
  // $reader->close(); // not needed as it will be automatically called when there are no more lines

} catch (Exception $e) {
    print $e->getMessage() . "\n";
}

 
 
   while (($line = $reader->getLine(Reader::SKIP_EMPTY_LINES)) !== null) {
       print_r($line);
   }
   
 


 
iedsch\Data\File\CsvReader;
use Fiedsch\Data\Augmentation\Augmentor;
use Fiedsch\Data\Augmentation\Provider\TokenServiceProvider;
use Fiedsch\Data\File\CsvWriter;
  
try {

  $augmentor = new Augmentor();
 
  $augmentor->register(new TokenServiceProvider());
  
  $augmentor->addRule('token', function (Augmentor $augmentor, $data) {
     return [ 'token' => $augmentor['token']->getUniqueToken() ];
   });
  
   $reader = new CsvReader("testdata.csv", ";");
   
   $writer = new CsvWriter("testdata.augmented.txt", "\t");
   
   $header_written = false;
   
   while (($line = $reader->getLine(Reader::SKIP_EMPTY_LINES)) !== null) {
     $result = $augmentor->augment($line);
     if (!$header_written) {
        $writer->printLine(array_merge(['input_line'], array_keys($result), $reader->getHeader()));
        $header_written = true;
     }
     $writer->printLine(array_merge([$reader->getLineNumber()], $result, $line));
   }
   
   $writer->close();
 
 } catch (Exception $e) {
     print $e->getMessage() . "\n";
 }
 

 
  
 edsch\Data\Utility\TokenCreator;
 use Fiedsch\Data\File\Writer;


$creator = new TokenCreator(10, TokenCreator::UPPER);

$output = new Writer('mytokens.txt');
$numTokens = 1000;

while ($numTokens-- > 0) {
  $token = $creator->getUniqueToken();
  $output->printLine([$token]);
}
$output->close();

  // same as above, exept 
  // $token = $creator->getUniqueToken();
  // becomes
  $token = $creator->cretateToken();