Skip to content

php-lights/php-data-url

Folders and files

NameName
Last commit message
Last commit date
Jan 30, 2022
Dec 13, 2024
Dec 13, 2024
Dec 13, 2024
Oct 22, 2020
Dec 13, 2024
Jan 30, 2022
Dec 13, 2024
Feb 25, 2021
Dec 13, 2024
Dec 23, 2024
Dec 23, 2024
Dec 13, 2024
Dec 13, 2024

Repository files navigation

DataUrl

Packagist License CI 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 2397.

Install

This requires a minimum PHP version of v8.2.

composer require neoncitylights/data-url

Usage

<?php

use Neoncitylights\DataUrl\DataUrlParser;
use Neoncitylights\MediaType\MediaTypeParser;

$dataUrlParser = new DataUrlParser( new MediaTypeParser() );
$dataUrl = $dataUrlParser->parseOrNull( '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

This software is licensed under the MIT license (LICENSE or https://opensource.org/license/mit/).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.