我有一个照片库,其中包含一个简单的 ul 类别列表。 类别是我服务器上的文件夹。 如果文件夹名为“Ödla”,则该类别也被命名为“Ödla”。 是否可以仅在类别而不是服务器上的实际文件夹中将“Ödla”中的“Ö”替换为“o”。我不想使用 mysql。
希望你明白我的意思。
编辑:类别只是文本链接
- 厄德拉
- 第 2 类
在此示例中,我的服务器上有两个名为“Ödla”和“Category 2”的文件夹
我只想重命名类别链接,而不是文件夹。
最佳答案
您始终可以使用 PHP 函数 rename()
。使用@steven_desu 的 str_replace 方法,您可以使用新名称调用旧文件夹的重命名。查看文档。
http://www.php.net/manual/en/function.rename.php
编辑
例子:
<?php
// Create arrays with special chars
$o = array('Ò','Ó','Ô','Õ','Ö','ò','ó','ô','õ','ö');
// Remember to remove the slash at the end otherwise it will not work
$oldname = '/path/to/directory/Ödla';
// Get the directory name
$old_dir_name = substr($oldname, strrpos($oldname, '/') + 1);
// Replace any special chars with your choice
$new_dir_name = str_replace($o, 'O', $old_dir_name);
// Define the new directory
$newname = '/path/to/new_directory/' . $new_dir_name;
// Renames the directory
rename($oldname, $newname);
?>
请检查一下这个?
关于PHP重命名文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3924049/