繁体   English   中英

带有PHP

[英]Bulk str_replace sub-folder names with PHP

我有很多子文件夹在其名称中具有空格underlines but could someone please tell me why it isn't working? Cheers.

<?php  
 $dir = 'https://www.example.com/image/catalog/TEMP';

 if (is_dir($dir)) {
     if ($dh = opendir($dir)) {
         while (($foldername = readdir($dh)) !== false) {
               
             rename($dir.$foldername, str_replace(" ","_",$dir.$foldername));
   
         }
         closedir($dh);
     }
 }
?>
<?php  
const DS = DIRECTORY_SEPARATOR;

$dir = 'https://www.example.com/image/catalog/TEMP';

if (!is_dir($dir)) exit(0);

$dh = opendir($dir);

while ($item = readdir($dh)) :
  $current = $dir . DS . $item; 
  $new = $dir . DS . str_replace(" ", "_", $item); 
  rename($current, $new);
endwhile;
   
closedir($dh);
     

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM