note 30152 added to ref.filesystem

From: Date: Sat, 08 Mar 2003 13:18:51 +0000
Subject: note 30152 added to ref.filesystem
Groups: php.notes 
Request: Send a blank email to php-notes+get-45001@lists.php.net to get a copy of this message
This is a function I use to determine if a file contains Binary information. I use this for my search engine so that it doesn't try to index files like .zip or .mp3 or any other file that doesn't contain readable information. It makes use of the Character Type Extension if it's loaded, if it's not then it uses Regular Expressions. function is_binary($link) { $tmpStr = ''; @$fp = fopen($link, 'rb'); @$tmpStr = fread($fp, 256); @fclose($fp); if($tmpStr != '') { $tmpStr = str_replace(chr(10), '', $tmpStr); $tmpStr = str_replace(chr(13), '', $tmpStr); $tmpInt = 0; for($i =0; $i < strlen($tmpStr); $i++) { if( extension_loaded('ctype') ) { if( !ctype_print($tmpStr[$i]) ) $tmpInt++; } else { if( !eregi("[[:print:]]+", $tmpStr[$i]) ) $tmpInt++; } } if($tmpInt > 5) return(0); else return(1); } else return(0); } -- http://www.php.net/manual/en/ref.filesystem.php http://master.php.net/manage/user-notes.php?action=edit+30152 http://master.php.net/manage/user-notes.php?action=delete+30152 http://master.php.net/manage/user-notes.php?action=reject+30152

« previous php.notes (#45001) next »