Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yusufkandemir/microdata-parser

Parse microdata from HTML documents with ease. PHP Implementation of W3C Microdata to JSON Specification.
https://github.com/yusufkandemir/microdata-parser

microdata parser php-library

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# microdata-parser

[![Latest Version on Packagist][ico-version]][link-packagist]
[![PHP Version Support][ico-php-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Tests][ico-tests]][link-tests]
[![Quality Checks][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-packagist]

This package aims to implement [W3C Microdata to JSON Specification](https://www.w3.org/TR/microdata/#json).

**microdata-parser** extracts microdata from documents.

## Installation

Via Composer

```bash
$ composer require yusufkandemir/microdata-parser
```

## Usage

##### PHP

```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

```html




Test Product


```

##### Result as JSON

```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

```bash
$ composer test
```

## Contributing

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## Credits

- [Yusuf Kandemir][link-author]
- [All Contributors][link-contributors]

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[ico-version]: https://img.shields.io/packagist/v/yusufkandemir/microdata-parser.svg?style=flat-square
[ico-php-version]: https://img.shields.io/packagist/php-v/yusufkandemir/microdata-parser?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-tests]: https://img.shields.io/github/actions/workflow/status/yusufkandemir/microdata-parser/run-tests.yml?style=flat-square&logo=github&label=tests
[ico-code-quality]: https://img.shields.io/github/actions/workflow/status/yusufkandemir/microdata-parser/analyze-quality.yml?style=flat-square&logo=github&label=quality
[ico-downloads]: https://img.shields.io/packagist/dt/yusufkandemir/microdata-parser.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/yusufkandemir/microdata-parser
[link-tests]: https://github.com/yusufkandemir/microdata-parser/actions/workflows/run-tests.yml
[link-code-quality]: https://github.com/yusufkandemir/microdata-parser/actions/workflows/analyze-quality.yml
[link-author]: https://github.com/yusufkandemir
[link-contributors]: ../../contributors