[英]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.