PHP Classes

File: class.data_uri.example.php

Recommend this page to a friend!
  Classes of Uku-Kaarel Jo~esaar  >  Data URI  >  class.data_uri.example.php  >  Download  
File: class.data_uri.example.php
Role: Example script
Content type: text/plain
Description: Example usage of class
Class: Data URI
Generate data URL to embed binaries in links
Author: By
Last change: reviewed beacause main class is changed
Date: 8 years ago
Size: 1,589 bytes



Class file image Download

// Example

$du = new data_uri;
/* Apache mime magic file */
$uridata1 = $du->fromFile($pathToScriptDir.'elephpant.jpg');
$urihtml =
"\xEF\xBB\xBF" . //UTF-8
'<'.'?xml version="1.0" encoding="UTF-8" ?'.'>
 <meta name="skip" value="other stuff" />
 <meta charset="UTF-8" />
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <img src="'
.$uridata1.'" height="117" width="133" alt="elephpant.jpg" />
 <p>ÜÕÖÄ £é</p>
$du->set_encoding('raw'); // to raworlencode octets %00
$uridata3 = $du->fromData($urihtml ,'text/html' ,'auto' ); //auto detects as utf-8
//$uridata3 = $du->fromData($urihtml ,'unknown/html' ,'auto' ); //skip

?><!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
body {
    background:url('<?=$uridata1?>') repeat-y;


<img src="<?=$uridata1?>" height="117" width="133" alt="An elephant"
    style="margin-left:266px;border:3px solid blue;" />
 <pre><?php print_r($du->get_execution_data()); ?></pre>

For more information send a message to info at phpclasses dot org.