directorize() function
April 14, 2009 at 03:28 PM · Posted under Blog · Tagged with directory, function, php
function directorize($dir) {
return strtolower(preg_replace('/[^a-z0-9\-]/i', '', str_replace(' ', '-', $dir)));
}
What this function does is replaces all instances of any character that is not a letter, number, or dash (we replace spaces with dashes for directory creation), with nothing, so an example such as:
The Lazy Fox is Just plain lazy!
Would return: the-lazy-fox-is-just-plain-lazy.
Enjoy!
Permalink