有人用过php_strip_whitespace这个方法没,我获得的结果要么是大空白,要么是半截代码,好奇怪
rename.php
<?php
function IsAnimatedGif($filename){
$fp = fopen($filename, 'rb');
$filecontent = fread($fp, filesize($filename));
fclose($fp);
return strpos($filecontent,chr(0x21).chr(0xff).chr(0x0b).'NETSCAPE2.0') === FALSE?0:1;
}
//echo IsAnimatedGif("test.gif");
$files = scandir('images');
//print_r($files);
if($files){
foreach($files as $key => $v){
if(IsAnimatedGif('images/'.$v)){
//$img_info = getimagesize('images/'.$v);//Array ( [0] => 400 [1] => 203 [2] => 1 [3] => width="400" height="203" [bits] => 7 [channels] => 3 [mime] => image/gif )
//$img_info = basename('images/'.$v);//pic_uc_1490747710825.jpg
$img_info = pathinfo('images/'.$v);//Array ( [dirname] => images [basename] => pic_uc_1490747710825.jpg [extension] => jpg [filename] => pic_uc_1490747710825 )
if($img_info['extension'] != 'gif'){
rename('images/'.$v, 'images/'.$img_info['filename'].'.gif');
}
}
}
echo 'success';
}
?>
strip_whitespace.php
<?php
if(is_file('rename.php')){
$content = php_strip_whitespace('rename.php');
}else{
echo 'rename.php is not a file';die;
}
print_r($content);
?>
这是执行strip_whitespace.php最终结果:
$v){ if(IsAnimatedGif('images/'.$v)){ $img_info = pathinfo('images/'.$v); if($img_info['extension'] != 'gif'){ rename('images/'.$v, 'images/'.$img_info['filename'].'.gif'); } } } echo 'success'; } ?>