PHP code example of kedrigern / phpio

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

    

kedrigern / phpio example snippets


$files = new \Kedrigern\phpIO\Files();

$cat = function($file) {
	echo "Filename: $file \n";
	echo file_get_contents($file);
	echo "\n";
};

$files->dir('*.txt')->call($cat)->delete();

$fill = function($file) {
	file_put_contents($file, "Some data.");
};

$files->dir('*.txt')->writeable()->call($fill)->move('archive', true);

$parseIntFromFile = function($file) {
	return intval(file_get_contents($file));
};

$postSum = function($results) {
	return array_sum($results);
};

$files->dir('*.num')->call($parseIntFromFile, $postSum, $log);

// now $log['post'] contains sum