yusufkandemir / microdata-parser
Parse microdata from HTML documents with ease. PHP Implementation of W3C Microdata to JSON Specification.
Installs: 41 835
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 3
Forks: 10
Open Issues: 0
Requires
- php: ^8.1
- ext-dom: *
- ext-libxml: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.54
- pestphp/pest: ^1.23.1
- phpstan/phpstan: ^1.10.67
Suggests
- ext-json: Needed to convert results to JSON
This package is auto-updated.
Last update: 2024-10-31 00:22:03 UTC
README
This package aims to implement W3C Microdata to JSON Specification.
microdata-parser extracts microdata from documents.
Installation
Via Composer
$ composer require yusufkandemir/microdata-parser
Usage
PHP
use YusufKandemir\MicrodataParser\Microdata; $microdata = Microdata::fromHTMLFile('source.html')->toJSON(); /* Other sources: fromHTML() // from HTML string fromDOMDocument() // from DOMDocument object Other output methods: toArray() // to Associtive PHP Array toObject() // to PHP Object (stdClass) */
Source as HTML
<!-- source.html --> <div itemscope itemtype="http://schema.org/Product"> <img itemprop="image" src="http://shop.example.com/test_product.jpg" /> <a itemprop="url" href="http://shop.example.com/test_product"> <span itemprop="name">Test Product</span> </a> </div>
Result as JSON
{ "items": [ { "type": [ "http://schema.org/Product" ], "properties": { "image": [ "http://shop.example.com/test_product.jpg" ], "url": [ "http://shop.example.com/test_product" ], "name": [ "Test Product" ] } } ] }
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.