Fork of yusufkandemir/microdata-parser
Go to file
Yusuf Kandemir d2f6572125 Added a test for itemid and content attributes 2018-12-18 11:29:31 +03:00
.github Added package skeleton 2018-11-10 21:57:03 +03:00
src Added null type to docblock 2018-12-18 10:00:58 +03:00
tests Added a test for itemid and content attributes 2018-12-18 11:29:31 +03:00
.editorconfig Added package skeleton 2018-11-10 21:57:03 +03:00
.gitattributes Added package skeleton 2018-11-10 21:57:03 +03:00
.gitignore Added package skeleton 2018-11-10 21:57:03 +03:00
.scrutinizer.yml Added package skeleton 2018-11-10 21:57:03 +03:00
.styleci.yml Added package skeleton 2018-11-10 21:57:03 +03:00
.travis.yml Update .travis.yml 2018-11-15 09:17:23 +03:00
CHANGELOG.md :) 2018-11-14 23:10:01 +03:00
LICENSE.md Added package skeleton 2018-11-10 21:57:03 +03:00
README.md Clarified Readme [ci skip] 2018-12-17 20:48:14 +03:00
composer.json Update composer.json 2018-11-15 08:51:48 +03:00
phpcs.xml.dist Added package skeleton 2018-11-10 21:57:03 +03:00
phpunit.xml.dist Added package skeleton 2018-11-10 21:57:03 +03:00

README.md

microdata-parser

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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" ]
      }
    }
  ]
}

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.