atk14/string-buffer

StringBuffer 是一个提供高效字符串缓冲操作的 PHP 类

v1.2.4 2021-05-24 13:18 UTC

This package is auto-updated.

Last update: 2024-08-30 01:12:14 UTC


README

Build Status

StringBuffer 是一个提供高效字符串缓冲操作的 PHP 类

基本用法

$sb = new StringBuffer();
$sb->addString("Hello World!\n");
$sb->addFile("path/to/file");
$length = $sb->getLength();
$sb->printOut();

将 StringBuffer 转换为字符串

$string = (string)$sb;
// or
$string = "$sb";
// or
$string = $sb->toString();

临时缓冲区

您可以使用 StringBuffer 来存储和操作大量数据,而不会消耗过多的内存。

$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);

可以定义常量 TEMP 来指定存储字符串缓冲区项的所需临时目录。

define("TEMP","/path/to/temp/");

安装

使用 Composer 安装 StringBuffer。

cd path/to/your/project/
composer require atk14/string-buffer

许可证

StringBuffer 是免费软件,根据 MIT 许可证 分发