Zip, complete rewrite and write mode added
Posted by Pierre in
PHP
Monday, March 6. 2006
A couple of months ago I wrote a zip extension and I finally managed to commit it in pecl. It is a complete rewrite and does not use anything from the old version (Sterling’s Zip extension). It uses a library called libzip (see their site), no more zzlib.
It is 100% backward compatible, you can use your old code transparently.
The main changes are:
For PHP 5.1.x and up
- Add create, modify and write support, from files or strings
- stream support (read only)
- OO interface
For PHP 4.x and 5.0.x
- Better zip read support, broken zip files with zzlib may now work smoothly
For the old APIs, you can read the good old PHP manual. There is no documentation yet, but the examples contain all new features. It is the very first releases, consider it as alpha ![]()
Comments and feedbacks welcome, using the pecl list or using the bugs reporting tool, or as comments here.
Windows versions are avaible on pecl4win (only 5.1+), *nix users: pecl install zip-1.1.2 (or zip-alpha)
Thanks to Mike, Frank and Edin for the windows compilation fixes and Marcus for some leak elimination ![]()
Some examples:
- Extract all files
[php] <?php $zip = new Zip(); $zip->open("test.zip"); $zip->extractTo('where/you/want/it'); ?> - Extract one (or many) file:
[php] <?php $zip = new Zip(); $zip->open("test.zip"); $files = array('test', 'testdir/test2'); $zip->extractTo("./testext/path/to", $files); ?> - Open a stream to a entry
[php] <?php $z = new Zip(); $z->open('test1.zip'); $fp = $z->getStream('test.txt', "r"); if(!$fp) exit(" "); while (!feof($fp)) { $contents .= fread($fp, 2); echo "$contents "; } ?> - Create a zip
[php] <?php $zip = new Zip(); $zip->open("test1.zip"); $zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt. "); $zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt. "); $zip->addFile("too.php", "testfromfile.php"); echo $zip->numFiles . " "; ?>
XMLWriter, 2.0.4 is out
Posted by Pierre in
PHP
Monday, March 6. 2006
A small release with only new features, all done by Rob Richards:
- #6267, Implement xmlTextWriterWriteRaw
- #6266, Implement xmlTextWriterFullEndElement
- #6177, xmlwriter_write_dtd_element inconsistent parameters between function/method
You can fetch it from the PECL xmlwriter homepage, or using
pecl install xmlwriter or pecl upgrade xmlwriter



