neoncitylights/data-url

Allows working with data URLs as entity objects in PHP

v2.0.0 2020-11-13 02:31 UTC

README

Packagist Version GitHub PHP Composer codecov

A small PHP library for dealing with data URLs, which contain a media type and an encoded base64 string.

This library fully conforms to RFC 23971.

Install

composer require neoncitylights/data-url

Usage

<?php

use Neoncitylights\DataUrl\DataUrlParser;

$dataUrlParser = new DataUrlParser();
$dataUrl = $dataUrlParser->parse( 'data:text/plain;base64,VGhlIGZpdmUgYm94aW5nIHdpemFyZHMganVtcCBxdWlja2x5Lg==' );

print( $dataUrl->getMediaType()->getEssence() );
// 'text/plain'

print( $dataUrl->getData() );
// `VGhlIGZpdmUgYm94aW5nIHdpemFyZHMganVtcCBxdWlja2x5Lg==`

print( $dataUrl->getDecodedValue() );
// 'The five boxing wizards jump quickly.'

License

DataUrl is licensed under the MIT license.