Jump to content

Rename folder with php


discoloser

Recommended Posts

Hello,

 

I have a photo gallery with a simple ul list of categories.

The categories are folders on my server.

If a folder is named "Ödla" then the category is named "Ödla" too.

Is it possible to replace Ö in "Ödla" with o.

I onlyt want to change the name of the ul list, not the actual folder on the server.

 

I hope you understand what I mean.

Link to comment
https://forums.phpfreaks.com/topic/215777-rename-folder-with-php/
Share on other sites

str_replace() should work for you. You can define an array of characters to be replaced and an array of characters that will do, errr,  the replacing (for lack of a better phrase).

 

I´ve tried str_replace(), but "odla" couldn´t find the images in "Ödla"

I´ll try to explain more clearly:

My image gallery is based on folders. Every folder is a category in the gallery.

If the folder´s name is "Öland" I want the url to be "oland".

Can I do this without changing the name of the folder and without using database?

When you're echoing the list of folders, echo the url without using str_replace(), and the link with str_replace(). For example:

 

<?php
$folder_list = array( 'folder1', 'folder2', 'folder3' );
$needles = range( 1,3 );
$replacements = range( 'A','C' );
foreach( $folder_list as $v ) {
    echo "<a href=\"$v\">Link to " . str_replace($needles, $replacements, $v) . "</a><br>\n";
}
?>

 

The above returns this source:

<a href="folder1">Link to folderA</a><br>

<a href="folder2">Link to folderB</a><br>

<a href="folder3">Link to folderC</a><br>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.