1. Go to this page and download the library: Download phillarmonic/cpf-cnpj 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/ */
phillarmonic / cpf-cnpj example snippets
use Phillarmonic\CpfCnpj\CPF;
$cpf = new CPF('123.456.789-09');
if ($cpf->isValid()) {
echo "The CPF is valid.";
} else {
echo "The CPF is not valid.";
}
use Phillarmonic\CpfCnpj\CPF;
$cpf = new CPF('12345678909');
$formattedCpf = $cpf->format();
if ($formattedCpf !== false) {
echo "Formatted CPF: " . $formattedCpf; // Outputs: 123.456.789-09
} else {
echo "Invalid CPF, unable to format.";
}
use Phillarmonic\CpfCnpj\CNPJ;
$cnpj = new CNPJ('12.345.678/0001-95');
if ($cnpj->isValid()) {
echo "The CNPJ is valid.";
} else {
echo "The CNPJ is not valid.";
}
use Phillarmonic\CpfCnpj\CNPJ;
$cnpj = new CNPJ('12345678000195');
$formattedCnpj = $cnpj->format();
if ($formattedCnpj !== false) {
echo "Formatted CNPJ: " . $formattedCnpj; // Outputs: 12.345.678/0001-95
} else {
echo "Invalid CNPJ, unable to format.";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.