简体   繁体   English

如何将破折号替换为目录中的空格

[英]how to replace dash to space in directory

I have a Folder which name is 我有一个文件夹,名称是

Apple-photos 苹果照片

and i want to replace - to space so how can i do this this code is showing directory name like this Apple-photos and i want like this Apple photos 而且我想替换-要保留空间,所以我该如何执行此代码显示像这样的Apple照片的目录名称,而我想要这样的Apple照片

<?php echo basename(pathinfo($image, PATHINFO_DIRNAME));?>

i have one more code to replace - to space but how can i merge it in my code here is replace code 我还有一个要替换的代码-空间,但是如何在我的代码中合并它呢?

<?php echo ''.ucwords(str_replace("-"," ",$title)).'';?>

i am not expert in php please help me to fix this issue thanks 我不是php方面的专家,请帮助我解决此问题,谢谢

complete code 完整的代码

<?php

    //path to directory to scan. i have included a wildcard for a subdirectory
    $directory = "albums/*/";

    //get all image files with a .jpg extension.
    $images = glob("" . $directory . "*.jpg");

array_multisort(array_map('filemtime', $images), SORT_DESC, $images);

?>

<?php $num_of_files = 0; $i=0; foreach ($images as $image):?>
<div class="item"><a href="<?php echo basename(pathinfo($image, PATHINFO_DIRNAME)); ?>.html" target="_blank">
<img class="lazyOwl" src="<?php echo $image ?>" />
<p><?php echo basename(pathinfo($image, PATHINFO_DIRNAME)); ?></p>
             </div>
<?php if (++$num_of_files == 3)break; ?>
  <?php if(++$i%3==0): ?>

<?php endif ?>

<?php endforeach ?>

This is just a basic way of doing it. 这只是一种基本的方法。

$old = "Apple-Photos";
$new = str_replace("-", " ", $old);

rename($old, $new);

If you need to grab the directory of a file, and then rename that. 如果需要获取文件的目录,然后重命名。 It will need additional code to strip out the exact directory from the path name and so on. 它将需要其他代码来从路径名中删除确切的目录,依此类推。

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

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