Fork of yusufkandemir/microdata-parser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Yusuf Kandemir d2f6572125 Added a test for itemid and content attributes 3 years ago
.github Added package skeleton 4 years ago
src Added null type to docblock 3 years ago
tests Added a test for itemid and content attributes 3 years ago
.editorconfig Added package skeleton 4 years ago
.gitattributes Added package skeleton 4 years ago
.gitignore Added package skeleton 4 years ago
.scrutinizer.yml Added package skeleton 4 years ago
.styleci.yml Added package skeleton 4 years ago
.travis.yml Update .travis.yml 4 years ago
CHANGELOG.md :) 4 years ago
LICENSE.md Added package skeleton 4 years ago
README.md Clarified Readme [ci skip] 3 years ago
composer.json Update composer.json 4 years ago
phpcs.xml.dist Added package skeleton 4 years ago
phpunit.xml.dist Added package skeleton 4 years ago

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.