atk14 / string-buffer
StringBuffer is a PHP class providing operations for efficient string buffering
Installs: 22 927
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.0
- atk14/files: >=1.5
Requires (Dev)
- atk14/tester: *
README
StringBuffer is a PHP class providing operations for efficient string buffering
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:
$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.
$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.
define("TEMP","/path/to/temp/");
Installation
Use the Composer to install StringBuffer.
cd path/to/your/project/
composer require atk14/string-buffer
Licence
StringBuffer is free software distributed under the terms of the MIT license