PHP code example of anglemx / mexico-rfc

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

    

anglemx / mexico-rfc example snippets


$dob = \DateTime::createFromFormat('Y-m-d', '1989-07-15');
$rfc = RFC::createForNaturalPerson('Jose Ramiro', 'Gutierrez', 'Hernández', $dob);

echo $rfc->getRfc(); // GUHR890715
echo $rfc->getRfcComplete(); // GUHR890715G54

echo (RFC::isValid('INVALID_12313') ? 'Yes' : 'No'); // No
echo (RFC::isValid('GUHR890715G54') ? 'Yes' : 'No'); // Yes

echo (RFC::isValidWithoutHomoclave('GUHR890715') ? 'Yes' : 'No'); // Yes

$rfc = RFC::createFromRfcString('GUHR890715G54');

if ($rfc === null) {
    die('Invalid RFC string');
}

echo ($rfc->isGeneric() ? 'Yes' : 'No'); // No
echo ($rfc->isNaturalPerson() ? 'Yes' : 'No'); // Yes
bash
php vendor/bin/phpunit tests/BuildTest.php
php vendor/bin/phpunit tests/ValidationTest.php