1. Go to this page and download the library: Download darkghosthunter/rut-utils 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/ */
darkghosthunter / rut-utils example snippets
use DarkGhostHunter\RutUtils\Rut;
// Create a RUT using its numbers and verification digit separately.
$rutA = new Rut('14328145', 0);
// ...even if the RUT is malformed
$rutB = new Rut(10000, 'foo');
use DarkGhostHunter\RutUtils\Rut;
// Create a RUT using its numbers and verification digit separately.
$rutA = Rut::make('14328145', 0);
// You can also use a whole string.
$rutB = Rut::make('14.328.145-0');
// And even malformed ones with invalid characters
$rutC = Rut::make('asdwdasd14.32.814.5-0');
use DarkGhostHunter\RutUtils\Rut;
$malformed = Rut::make('not-a-rut');
if (!$malformed) {
echo 'This RUT is bad!';
}
use DarkGhostHunter\RutUtils\Rut;
$validA = Rut::make('14328145', 0, 'this is valid');
echo $validA; // "14.328.145-0"
$validB = Rut::make('14.328.145-0', function () {
return 'also valid';
});
echo $validB; // "14.328.145-0"
$invalid = Rut::make('18.765.432-1', null, 'this is invalid');
echo $invalid; // "this is invalid"
use DarkGhostHunter\RutUtils\Rut;
$validA = Rut::makeOrThrow('18.765.432', 1);
// [!] [InvalidRutException]
use DarkGhostHunter\RutUtils\Rut;
// Create multiple RUTs
$rutsA = Rut::many('14.328.145-0', '14.328.145-0');
// Or issue an array of multiple RUTs
$rutsB = Rut::many([
'14.328.145-0',
'7976228-8',
['14.328.145', 0]
]);
use DarkGhostHunter\RutUtils\Rut;
// Let's create first the RUT:
$rut = Rut::make(14328145, 0);
// Return the RUT as a string
echo $rut; // 14.328.145-0
// You can get number or verification digit as an array
echo $rut['num']; // 14328145
echo $rut['vd']; // 0
// ...or as an object
echo $rut->num; // 14328145
echo $rut->vd; // 0