php 怎么去掉文件名中的中文 rename("山水20061813.jpg ", 20061813.jpg"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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 中的非空项是被改名的信息 试试这个思路while($file == readdir(opendir($dir)){ if(preg_match('/[^\x00-\xff]*[0-9]*\.jpg/',$str,$match) { $file = $match[0]; }} //遍历目录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";} php正则表达式获取div标签中的a标签href问题 php如何动态输出这段js代码,愁死,求高手帮助一下。 求教section 循环问题 想转行做IT,请大家给我点意见 SQL语句出错 PHPer,想说爱你是很不容易的事 PHP函数中包含普通html代码问题 身份证验证和银行转账的问题? 一个ip上怎么实现两个网站呀?急急急!! 基本学完了,请问该怎么继续,学习thinkphp吗? 根据IP判断地区 日期变量的操作问题
$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 中的非空项是被改名的信息
while($file == readdir(opendir($dir))
{
if(preg_match('/[^\x00-\xff]*[0-9]*\.jpg/',$str,$match)
{
$file = $match[0];
}
}
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";
}