StringBuffer
, (*1)
StringBuffer is a PHP class providing operations for efficient string buffering, (*2)
Basic usage
$sb = new StringBuffer();
$sb->addString("Hello World!\n");
$sb->addFile("path/to/file");
$length = $sb->getLength();
$sb->printOut();
Converting StringBuffer into a string:, (*3)
$string = (string)$sb;
// or
$string = "$sb";
// or
$string = $sb->toString();
Temporary buffer
You can use StringBuffer to store and manipulate large chunks of data without consuming excessive memory., (*4)
$buffer = new StringBufferTemporary();
// read something big in chunks
$buffer->add($megabyte);
$buffer->add($megabyte);
$buffer->add($megabyte);
$buffer->add($megabyte);
$buffer->add($megabyte);
// and so on... :)
$buffer->printOut();
// or
$buffer->writeToFile($target_filename);
Constant TEMP can be defined in order to specify the desired temporary directory for storing string buffer items., (*5)
define("TEMP","/path/to/temp/");
Installation
Use the Composer to install StringBuffer., (*6)
cd path/to/your/project/
composer require atk14/string-buffer
Licence
StringBuffer is free software distributed under the terms of the MIT license, (*7)