PHP code example of pauloalmeidasilva / cpfcnpj-validation

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

    

pauloalmeidasilva / cpfcnpj-validation example snippets



Src\Validator;

var_dump(Validator::validate('529.982.247-25')); // true
var_dump(Validator::validate('04252011000110')); // true (CNPJ sem pontuação)


Src\Cpf;
use Src\Validator;

$cpf = Cpf::generate();            // formatado por padrão
$cpfRaw = Cpf::generate(false);    // sem formatação (apenas dígitos)

var_dump($cpf);
var_dump(Validator::validate($cpfRaw));


Src\Formatter;

echo Formatter::formatCpf('52998224725');    // 529.982.247-25
echo Formatter::formatCnpj('04252011000110'); // 04.252.011/0001-10
echo Formatter::sanitize('529.982.247-25');  // 52998224725
echo Formatter::autoFormat('04252011000110'); // 04.252.011/0001-10
bash
php example/example_cpf_cli.php