Skip to content

Parse microdata from HTML documents with ease. PHP Implementation of W3C Microdata to JSON Specification.

License

Notifications You must be signed in to change notification settings

eboye/microdata-parser

 
 

Repository files navigation

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:https://schema.org/Product">
  <img itemprop="image" src="http:https://shop.example.com/test_product.jpg" />
  <a itemprop="url" href="http:https://shop.example.com/test_product">
    <span itemprop="name">Test Product</span>
  </a>
</div>
Result as JSON
{
  "items": [
    {
      "type": [ "http:https://schema.org/Product" ],
      "properties": {
        "image": [ "http:https://shop.example.com/test_product.jpg" ],
        "url": [ "http:https://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.

About

Parse microdata from HTML documents with ease. PHP Implementation of W3C Microdata to JSON Specification.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 82.8%
  • HTML 17.2%