(PHP ActiveX) Append Encoded Binary Data to StringBuilder
Demonstrates how to append encoded binary data to the contenets of a StringBuilder.
<?php
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.BinData')
$bd = new COM("Chilkat.BinData");
$success = $bd->LoadFile('qa_data/jpg/starfish.jpg');
if ($success == 0) {
print '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.
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.StringBuilder')
$sb = new COM("Chilkat.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('\' }');
print $sb->getAsString() . "\n";
// Output looks like this:
// { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }
?>
|