Converting the text files into bzip file.


 

Converting the text files into bzip file.

This example will explain about converting text files into bzip file.

This example will explain about converting text files into bzip file.

Converting text  file into bzip file

In this example, you will see, how to convert a text file into bzip file. In this example, we have printed 'I am a good programmer' along with converting a file into bzip file. 

Opne the PHP tag and first select a file to be converted into bzip file.

Open the file and write into bzip file

close the file. 

Again, open the file, and read it, close the file. 

close the php tag.

Select a file to be converted. into bzip file. 

<?php
# Read and Write a bz2 file
$bzfilename = "text.bz2";
$string = " I am a good programmer.\n";
$bz2 = bzopen($bzfilename, "w"); 
bzwrite($bz2, $string);
bzclose($bz2);
$bz = bzopen($bzfilename, "r");
echo bzread($bz2, 10);
bzclose($bz2);
?>

The out put:
'I am a good programmer.'

Ads