rename("山水20061813.jpg ", 20061813.jpg");

解决方案 »

  1.   

    function foo($str) {
      $tmp = preg_replace('/[\x80-\xff]+/', '', $str);
      if($tmp != $str) {
        if(! file_exists($tmp)) {
          rename($str, $tmp);
          return "$str to $tmp";
        }
        return "cat rename $str to $tmp";
      }
      return '';
    }$ar = array_map('foo', glob('目录/*.jpg'));$ar 中的非空项是被改名的信息
      

  2.   

    试试这个思路
    while($file == readdir(opendir($dir))
    {
     if(preg_match('/[^\x00-\xff]*[0-9]*\.jpg/',$str,$match)
      {
        $file = $match[0];
      }
    }
      

  3.   

    //遍历目录
    class get_all_files
    {
        var $lists = array();
        function list_all_files($dir){
        if(is_dir($dir)){ 
            $dh = opendir($dir);
        } else { 
            return;
        }
        while($file = readdir($dh)){
            if($file=="." || $file=="..") continue;
            $newdir = $dir."/".$file;
            if(is_dir($newdir)){
                $this->list_all_files($newdir);
                $this->lists['dir'][]=$file;
            } else {
                $this->lists['file'][]=$file;
            }
        }
        closedir($dh);
        return $this->lists;
        }
    }//替换
    $f = new get_all_files;
    $s = $f-> list_all_files("./");
    foreach($s as $k)
    {
        $end = preg_replace('/[\x80-\xff]+/',"",$k);
        rename($k,$end);:w
        //echo "$end \n";
    }