PHP code example of innovaweb / chileanrut

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

    

innovaweb / chileanrut example snippets


Rut::format('123123123'); // return 12.312.312-3
Rut::format('123123123', false); // return 12312312-3
Rut::format('123123123', false, false); // return 123123123 (it is best to use the unformat function)

Rut::unformat('12.312.312-3'); // return 123123123

Rut::validate('12.312.312-3'); // return true

Rut::calculateDv(12312312); // return 3

Rut::getNumber('12312312-3'); // return 12312312
Rut::getNumber('12312312-3', true); // return 12.312.312

Rut::getDv('12312312-3'); // return 3

namespace App\Http\Controllers;

use Innovaweb\ChileanRut\Rut;

class RutController extends Controller
{
    public function index()
    {
        $format = Rut::format('123123123');
        $unformat = Rut::unformat($format);
        return [
            $format,
            $unformat,
            Rut::validate($unformat),
            Rut::calculateDv(12312312),
            Rut::getNumber($format, false),
            Rut::getDv($format),
        ];
    }
}