PHP
Chilkat2 PHP
Append Encoded Binary Data to StringBuilder
Demonstrates how to append encoded binary data to the contenets of a StringBuilder.Chilkat PHP Downloads
<?php
use Chilkat2\BinData;
use Chilkat2\StringBuilder;
$bd = new BinData();
try {
$bd->LoadFile('qa_data/jpg/starfish.jpg');
} catch (\Chilkat2\Exception $e) {
echo "Failed to load file.\n";
exit;
}
// For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
$sb = new StringBuilder();
$sb->Append('{ "jpg": "');
// GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
$bd->GetEncodedSb('base64', $sb);
$sb->Append('" }');
echo $sb->GetAsString(), "\n";
// Output looks like this:
// { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }