# PHP data://

PHPServer Side ProgrammingProgramming

## Introduction

The data URI scheme has been defined in RFC 2397, published in 1998. It provides a mechanism to include in-line data in web page as if it is an external resource. PHP provides data:// wrapper for data URI representation. The data URI is represented as per following syntax

## data:// syntax

data:[media type][;base64],data

parameters

media type − Default is text/plain

optional base64 extension base64, separated from the preceding part by a semicolon, ndicating that the data content is binary data, encoded using the Base64 scheme for binary-to-text encoding.

The data, separated from the preceding part by a comma (,). The data is a sequence of zero or more octets represented as characters.

## Examples

Following example encodes a string to base64 format and then uses it as data in data:// URI

<?php
$string="TutorialsPoint India (p) Ltd";$b64=base64_encode($string); echo file_get_contents('data://text/plain;base64,'.$b64);
?>

We can also use file_get_contents() function to fetch data from a file to convert in bas64 format

<?php
$string=file_get_contents("test.txt");$b64=base64_encode($string); echo file_get_contents('data://text/plain;base64,'.$b64);
?>

Following example uses text/html as media type in data:// wrapper

<?php
$string=file_get_contents("test.html");$b64=base64_encode($string); echo file_get_contents('data://text/html;base64,'.$b64);
?>
Published on 22-Sep-2020 10:37:59
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.1620948314666748, "perplexity": 5236.339400853022}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-43/segments/1634323585449.31/warc/CC-MAIN-20211021230549-20211022020549-00009.warc.gz"}