note 100875 added to function.ziparchive-extractto

From: Date: Fri, 12 Nov 2010 08:29:08 +0000
Subject: note 100875 added to function.ziparchive-extractto
Groups: php.notes 
Request: Send a blank email to php-notes+get-173967@lists.php.net to get a copy of this message
This script will search for ".txt" file(any file name) inside test.zip archive. Suppose, 'example.txt' file is found then the script will copy 'example.txt' to "txt_files" directory and rename it to 'test.zip.txt' and will remove all the blank lines from 'test.zip.txt' and resave and will exit the loop without searching remaining entries. This script can be useful to extract .DIZ and GIF files to display ZIP archive details in your script. <?php $value="test.zip"; $filename="zip_files/$value"; $zip = new ZipArchive; if ($zip->open($filename) === true) { echo "Generating TEXT file."; for($i = 0; $i < $zip->numFiles; $i++) { $entry = $zip->getNameIndex($i); if(preg_match('#\.(txt)$#i', $entry)) { ////This copy function will move the entry to the root of "txt_files" without creating any sub-folders unlike "ZIP->EXTRACTO" function. copy('zip://'.dirname(__FILE__).'/zip_files/'.$value.'#'.$entry, 'txt_files/'.$value.'.txt'); $content = file_get_contents("txt_files/$value.txt"); $newcontent = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $content); file_put_contents("txt_files/$value.txt", "$newcontent"); break; } } $zip->close(); } else{ echo "ZIP archive failed"; } ?> enjoy PHP programming. Sachin Yadav ---- Server IP: 69.147.83.197 Probable Submitter: 117.196.215.49 ---- Manual Page -- http://www.php.net/manual/en/function.ziparchive-extractto.php Edit -- https://master.php.net/note/edit/100875 Del: integrated -- https://master.php.net/note/delete/100875/integrated Del: useless -- https://master.php.net/note/delete/100875/useless Del: bad code -- https://master.php.net/note/delete/100875/bad+code Del: spam -- https://master.php.net/note/delete/100875/spam Del: non-english -- https://master.php.net/note/delete/100875/non-english Del: in docs -- https://master.php.net/note/delete/100875/in+docs Del: other reasons-- https://master.php.net/note/delete/100875 Reject -- https://master.php.net/note/reject/100875 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173967) next »