-3

Couldn't find anything about this when searching and couldn't find any solution on my own and I would rather not use rename().

I want to simplify my work by naming my files based on my <title> I'd make a

$fileName = "This is my file name"; <title><?php echo $fileName = str_replace(' ', '-', strtolower($fileName )) ?></title>

Or simply

<title><?php strtolower("This is my file name") ?></title>

Output: this-is-my-file-name.html/php

Is there such a solution that can be set with a few lines of code, just as rename() but it targets itself and no other files?

mario.van.zadel
  • 2,919
  • 14
  • 23
  • 1
    You seem to want to slugify the file names. If that's the case then have a look at this for a previous conversation and set of answers [http://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string](http://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string) – jwpfox Sep 13 '16 at 07:14
  • Oh no, I want to change the name of the file that I'm editing/creating to automatically changed to the This is my title str_replace and all that is just ...for show, thx tho – NewbieLearner Sep 13 '16 at 07:20
  • I cannot understand what you are asking. – jwpfox Sep 13 '16 at 07:22
  • 1
    sorry about that, I have a file called website.html, I want to change this files name automatically by using a code that changes "website.html" to whatever is within the tags. Basically instead of changing the files name manually by right clicking and "rename" I'd be just put some code that changed it's name to be the same as whatever the title of the website is – NewbieLearner Sep 13 '16 at 07:26

1 Answers1

1

This is not the best way and im not entirely sure if it works because i cant try it myself atm but you can try it yourself and see what it does.

copy(basename(__FILE__), $fileName); // $filename being the name you want it to be.
unlink(__FILE__);

this basically just copies the file your working on to another name and then deletes the current one. Its definitly not the best way but it will only "rename" one file.