Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<bzreadLZF>
^Bzip2 FunctionsLast updated: Mon, 26 Oct 2026

bzwrite

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

bzwrite — Binary safe bzip2 file write

Description

function bzwrite(resource $bz, string $data, ?int $length = null): int|false

bzwrite() writes a string into the given bzip2 file stream.

Parameters

bz

The file pointer. It must be valid and must point to a file successfully opened by bzopen().

data

The written data.

length

If supplied, writing will stop after length (uncompressed) bytes have been written or the end of data is reached, whichever comes first.

Return Values

Returns the number of bytes written, or false on error.

Changelog

Version Description
8.0.0 length is nullable now.

Examples

Example #1 bzwrite() example

<?php
$str = "uncompressed data";
$bz = bzopen("/tmp/foo.bz2", "w");
bzwrite($bz, $str, strlen($str));
bzclose($bz);
?>

See Also

  • bzread() - Binary safe bzip2 file read
  • bzopen() - Opens a bzip2 compressed file

<bzreadLZF>
^Bzip2 FunctionsLast updated: Mon, 26 Oct 2026