neoncitylights/data-url

Allows working with data URLs as entity objects in PHP

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

This package is auto-updated.

Last update: 2024-04-22 01:25:06 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.

Footnotes

  1. Masinter, L., & X. (1998, August). The "data" URL scheme. Retrieved October 30, 2020, from https://tools.ietf.org/html/rfc2397