PHP code example of phpcfdi / cfdi-to-json
1. Go to this page and download the library: Download phpcfdi/cfdi-to-json 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/ */
phpcfdi / cfdi-to-json example snippets
declare(strict_types=1);
use PhpCfdi\CfdiToJson\JsonConverter;
$contents = file_get_contents('mi-archivo-xfdi.xml');
$json = JsonConverter::convertToJson($contents);
echo $json;
declare(strict_types=1);
use PhpCfdi\CfdiToJson\Factory;
/** @var DOMDocument $document */
$factory = new Factory();
$dataConverter = $factory->createConverter();
$rootNode = $dataConverter->convertXmlDocument($document);
$array = $rootNode->toArray();
var_export($array);