download phpExcel : https://phpexcel.codeplex.com/
<?php //data to make csv (may be from database, form, etc) $dbdata = array( array("name"=>"name1", "phone"=>"1010101001"), array("name"=>"name2", "phone"=>"1010101002") ); require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php'; require_once 'PHPExcel/Classes/PHPExcel.php'; // Create new PHPExcel object $objPHPExcel = new PHPExcel(); //setting column heading $objPHPExcel->getActiveSheet()->setCellValue('A1',"Name"); $objPHPExcel->getActiveSheet()->setCellValue('B1',"Phone"); //setting column body $i=2; //starting from row 2 bcz row 1 set to header foreach($dbdata as $data) { $objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$data['name']); $objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$data['phone']); $i++; } // Redirect output to a client’s web browser (Excel5) header('Content-type: text/csv'); header('Content-Disposition: attachment;filename="export.csv"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV'); $objWriter->save('php://output'); exit; ?>
For ziping and unziping we can use PHP ZipArchive libraries
bellow code will zip a folder recursively
<?php // Get real path for our folder echo $rootPath = realpath('Newfolder'); // Initialize archive object $zip = new ZipArchive(); $zip->open('file.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE ); // Create recursive directory iterator /** @var SplFileInfo[] $files */ $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY); foreach ($files as $name => $file) { // Skip directories (they would be added automatically) if (!$file->isDir()) { // Get real and relative path for current file $filePath = $file->getRealPath(); $relativePath = substr($filePath, strlen($rootPath) + 1); // Add current file to archive $zip->addFile($filePath, $relativePath); } } // Zip archive will be created only after closing object $zip->close(); ?>
For unzip
<?php $zip = new ZipArchive; $zip->open('sample.zip'); $zip->extractTo('./'); $zip->close(); ?>
Requirements :
http://php.net/manual/en/zip.requirements.php
Note : – php5.6 bellow version wi;; not support to create password protected zip, php5.6 and above will support to create password protected archives. All you need is to add this code ZipArchive::setPassword($password).
ref:
http://php.net/manual/en/book.zip.php, http://php.net/manual/en/zip.examples.php, http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php
<?php $array1 = array("color" => "red", 2, 4); $array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4); $result = array_merge($array1, $array2); print_r($result); ?>
Array ( [color] => green [0] => 2 [1] => 4 [2] => a [3] => b [shape] => trapezoid [4] => 4 )
<?php $v = "this is test <abcd>value1 ok</abcd> dont know tell me <abcd>value33 kooo ok</abcd> this is php regress <abcd>teeth value</abcd> ok how"; preg_match_all("#<abcd>([^<]+)</abcd>#", $v, $foo); echo implode("\n", $foo[1]); ?>
<?php include_once('../config/config.inc.php'); include_once('../config/settings.inc.php'); include_once('../classes/Cookie.php'); $cookie = new Cookie('psAdmin'); print_r($cookie); ?>