1. Go to this page and download the library: Download brazanation/documents 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/ */
brazanation / documents example snippets
use Brazanation\Documents\Cpf;
$document = Cpf::createFromString('06843273173');
if (false === $document) {
echo "Not Valid";
}
echo $document; // prints 06843273173
echo $document->format(); // prints 068.432.731-73
use Brazanation\Documents\Cpf;
use Brazanation\Documents\Exception\InvalidDocument as InvalidDocumentException;
try {
$document = new Cpf('06843273173');
echo $document; // prints 06843273173
echo $document->format(); // prints 068.432.731-73
} catch (InvalidDocumentException $e) {
echo $e->getMessage();
}
use Brazanation\Documents\Cnpj;
$document = Cnpj::createFromString('99999090910270');
if (false === $document) {
echo "Not Valid";
}
echo $document; // prints 99999090910270
echo $document->format(); // prints 99.999.090/9102-70
use Brazanation\Documents\CnpjAlfa;
$document = CnpjAlfa::createFromString('12ABC34501DE35');
if (false === $document) {
echo "Not Valid";
}
echo $document; 12ABC34501DE35
echo $document->format(); // prints 12.ABC.345/01DE-35
use Brazanation\Documents\Cnh;
$document = Cnh::createFromString('83592802666');
if (false === $document) {
echo "Not Valid";
}
echo $document; // prints 83592802666
echo $document->format(); // prints 83592802666
use Brazanation\Documents\Sped\NFe;
$document = NFe::createFromString('52060433009911002506550120000007801267301613');
if (false === $document) {
echo "Not Valid";
}
echo $document; // prints 52060433009911002506550120000007801267301613
echo $document->format(); // prints 5206 0433 0099 1100 2506 5501 2000 0007 8012 6730 1613
use Brazanation\Documents\PisPasep;
$document = PisPasep::createFromString('518.23129.49-1');
if (false === $document) {
echo "Not Valid";
}
echo $document; // prints 51823129491
echo $document->format(); // prints 518.23129.49-1
use Brazanation\Documents\Voter;
$document = Voter::createFromString('106644440302', 20, 42);
if (false === $document) {
echo "Not Valid";
}
echo $document; // prints 106644440302
echo $document->getSection(); // prints 0020
echo $document->getZone(); // prints 042
use Brazanation\Documents\StateRegistration;
// for Commercial São Paulo
$state = StateRegistration::SP('110.042.490.114');
echo $state; // prints 110042490114
echo $state->format(); // prints 110.042.490.114
// for Rural Producer São Paulo
$state = StateRegistration::SP('P011004243002');
echo $state; // prints P011004243002
echo $state->format(); // prints P-01100424.3/002
use Brazanation\Documents\StateRegistration;
$document = StateRegistration::createFromString('P011004243002', 'SP');
if (false === $document) {
echo "Not Valid";
}
use Brazanation\Documents\Cns;
$document = Cns::createFromString('242912018460005');
if (false === $document) {
echo "Not Valid";
}
echo $document; // prints 242912018460005
echo $document->format(); // prints 242 9120 1846 0005
use Brazanation\Documents\Renavam;
$document = Renavam::createFromString('61855253306');
if (false === $document) {
echo "Not Valid";
}
echo $document; // prints 61855253306
echo $document->format(); // prints 6185.525330-6