note 97485 added to function.ftruncate

From: Date: Thu, 22 Apr 2010 10:12:19 +0000
Subject: note 97485 added to function.ftruncate
Groups: php.notes 
Request: Send a blank email to php-notes+get-168499@lists.php.net to get a copy of this message
Simple script which will delete spaces from end of php files (suitable in big sites, when you are including many files before sending headers and without output buffering): function mapfiles($func,$filename,$level=0) { if(is_dir($filename)) { if($level>30) return; //limit recurence in case of looped dirs $handle=opendir($filename); while(($dirname=readdir($handle))!==false) { if($dirname=='.'||$dirname=='..') continue; mapfiles($func,$filename.'/'.$dirname,$level+1); } closedir($handle); } else { $func($filename); } } function scanfile($filename) { if(substr($filename,-4)!=".php") return; $ff=fopen($filename,"r+"); fseek($ff, -10, SEEK_END); $str=fread($ff,12); $matches=array(); if(preg_match('/\?>(\s+)$/',$str,$matches)) { $fsize=filesize($filename); ftruncate($ff, $fsize-strlen($matches[1])); } fclose($ff); } mapfiles("scanfile","."); ---- Server IP: 82.177.164.100 Probable Submitter: 79.190.157.69 ---- Manual Page -- http://www.php.net/manual/en/function.ftruncate.php Edit -- https://master.php.net/note/edit/97485 Del: integrated -- https://master.php.net/note/delete/97485/integrated Del: useless -- https://master.php.net/note/delete/97485/useless Del: bad code -- https://master.php.net/note/delete/97485/bad+code Del: spam -- https://master.php.net/note/delete/97485/spam Del: non-english -- https://master.php.net/note/delete/97485/non-english Del: in docs -- https://master.php.net/note/delete/97485/in+docs Del: other reasons-- https://master.php.net/note/delete/97485 Reject -- https://master.php.net/note/reject/97485 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168499) next »