Yusuf Kandemir
a4a5cce8d8
Refactored long switch case with duplicate code to lookup table
This is more performant(can be ignored but an extra) due to nature of lookup tables. Also it is more compact and has ease of extension. It is a little bit scary at the first sight though.
microdata-parser
This package aims to implement W3C Microdata 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" ]
}
}
]
}
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
Description
Languages
PHP
82.1%
HTML
17.9%