einfacharchiv / microdata
Extract billing data from HTML (supporting Microdata and JSON-LD)
Requires
- php: ^7.0 || ^8.0
- commerceguys/intl: ~1.0
- jkphl/micrometa: ~3.0
- nesbot/carbon: ~1.25|~2.0
README
This package provides an easy way to extract billing data from Microdata and JSON-LD in an HTML document.
Requirements
PHP 7.0 and later.
Installation
You can install this package via Composer. Run the following command:
composer require einfacharchiv/microdata
Usage
Extracting billing data from HTML is easy.
If an item is not present, the method returns null
.
$html = '<!doctype html><html lang="en"><head>...'; $microdata = new Microdata($html); // Get all invoice items foreach ($microdata->getItemsByType('Invoice') as $item) { // Available methods (string) $item->getBillingPeriod() ?: null; $item->getConfirmationNumber(); if ($item->getCustomer()) { (string) $item->getCustomer()->getIdentifier() ?: null; $item->getCustomer()->getName(); if ($item->getCustomer()->getAddress()) { $item->getCustomer()->getAddress()->getStreetAddress(); $item->getCustomer()->getAddress()->getPostOfficeBoxNumber(); $item->getCustomer()->getAddress()->getPostalCode(); $item->getCustomer()->getAddress()->getAddressLocality(); $item->getCustomer()->getAddress()->getAddressRegion(); (string) $item->getCustomer()->getAddress()->getAddressCountry() ?: null; } $item->getCustomer()->getEmail(); $item->getCustomer()->getTelephone(); $item->getCustomer()->getUrl(); $item->getCustomer()->getTaxId(); $item->getCustomer()->getVatId(); } (string) $item->getPaymentDueDate() ?: null; (string) $item->getPaymentMethod() ?: null; $item->getPaymentMethodId(); (string) $item->getPaymentStatus() ?: null; if ($item->getProvider()) { $item->getProvider()->getName(); if ($item->getProvider()->getAddress()) { $item->getProvider()->getAddress()->getStreetAddress(); $item->getProvider()->getAddress()->getPostOfficeBoxNumber(); $item->getProvider()->getAddress()->getPostalCode(); $item->getProvider()->getAddress()->getAddressLocality(); $item->getProvider()->getAddress()->getAddressRegion(); (string) $item->getProvider()->getAddress()->getAddressCountry() ?: null; } $item->getProvider()->getEmail(); $item->getProvider()->getTelephone(); $item->getProvider()->getUrl(); $item->getProvider()->getTaxId(); $item->getProvider()->getVatId(); } if ($item->getTotalPaymentDue()) { $item->getTotalPaymentDue()->getAmount(); // Returns an array with 'amount' and 'currency' } (string) $item->getIdentifier() ?: null; $item->getName(); $item->getUrl(); }
Contributing
Contributions are welcome.
We accept contributions via Pull Requests on Github.
Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improvement? Feel free to create an issue on GitHub, we'll try to address it as soon as possible.
If you've found a security issue, please email support@einfacharchiv.com instead of using the issue tracker.
Happy coding!
Credits
License
The MIT License (MIT). Please see License File for more information.