php8.5
Home/ Manual/ language / wrappers/ data://

data://

PHP function Edit on GitHub ✎

Data (RFC 2397)

Description

The data: (RFC 2397) stream wrapper.

Usage

  • data://text/plain;base64,

Options

AttributeSupported
Restricted by allow_url_fopenYes
Restricted by allow_url_includeYes
Allows ReadingYes
Allows WritingNo
Allows AppendingNo
Allows Simultaneous Reading and WritingNo
Supports stat()No
Supports unlink()No
Supports rename()No
Supports mkdir()No
Supports rmdir()No

Examples

Print data:// contents

php
<?php
// prints "I love PHP"
echo file_get_contents('data://text/plain;base64,SSBsb3ZlIFBIUAo=');
?>

Fetch the media type

php
<?php
$fp   = fopen('data://text/plain;base64,', 'r');
$meta = stream_get_meta_data($fp);

// prints "text/plain"
echo $meta['mediatype'];
?>

Source: language/wrappers/data.xml · from the official PHP manual (php/doc-en)