Liam Delahunty: Home | Tips | Web | Contact |
---|
Recommended laptop
under £500. Think I deserve a present? See my Amazon Wish List |
Online Filename ConversionThis form strips out non alpha numeric characters, coverts spaces to underscores and lowercases the string. Use the Dash option if you prefer dashes to underscores. Consecutive dashes or underscores will be deleted. I find it useful to take a document title and throw it through this to generate the file name. function convertFilename($newname,$dash){ if ($dash){ $sep ="-"; $sepb ="_"; }else{ $sep = "_"; $sepb ="-"; } $newname = eregi_replace("[^a-zA-Z0-9]", "$sep", $newname); $newname = eregi_replace("$sepb", "$sep", $newname); $newname = eregi_replace("$sep$sep", "$sep", $newname); $newname = eregi_replace("$sep\.", ".", $newname); $newname = eregi_replace("[$sep]$", "", $newname); $newname = "".$newname; $filename = strtolower($newname); while (eregi("$sep$sep",$filename)){ $filename=convertFilename($filename,$dash); } return $filename; } Share this! |