Folder Name Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • frizzle

    Folder Name Function

    Hi group!

    I have a code to process text, to make it url/folder fiendly. (code
    below)
    The only problem i have, is that the
    $foldername = ereg_replace("[^[:alnum:] ]","",$foldernam e);
    part deletes all spaces, but as you can see, i want spaces to become
    underscores,
    which are no ALNUM-chars.
    How can i solve this?

    Greetings Frizzle.

    ///// C O D E /////

    $foldername = stripslashes ( $_POST['foldername'] );
    //This erase white-spaces on the beginning and the end:
    $foldername = preg_replace('~ ^(\s*)(.*?)(\s* )$~m', "\\2", $foldername);
    // replace all weird chars
    $special_chars =
    array('À','Á',' Â','Ã','Ä','Å', 'Ç','È','É','Ê' ,'Ë','Ì','Í','Î ','Ï','Ñ','Ò',' Ó','Ô','Õ','Ö', 'Ù','Ú','Û','Ü' ,'Ý','à','á','â ','ã','ä','å',' ç','è','é','ê', 'ë','ì','í','î' ,'ï','ñ','ò','ó ','ô','õ','ö',' ù','ú','û','ü', 'ý','ÿ','C','c' ,'C','c');
    $special_replac ements =
    array('A','A',' A','A','A','A', 'C','E','E','E' ,'E','I','I','I ','I','N','O',' O','O','O','O', 'U','U','U','U' ,'Y','a','a','a ','a','a','a',' c','e','e','e', 'e','i','i','i' ,'i','n','o','o ','o','o','o',' u','u','u','u', 'y','y','C','c' ,'C','c');
    $foldername = str_replace($sp ecial_chars, $special_replac ements,
    $foldername);
    //erases all NON-alfanumerics
    $foldername = ereg_replace("[^[:alnum:] ]","",$foldernam e);
    // take out repetative spaces:
    $foldername = preg_replace('/\s\s+/', ' ', $foldername);
    $foldername = preg_replace('/\s/', '_', $foldername);
    $foldername = strtolower($fol dername);
    if ($foldername == ""){$folder name = "untitled"; }

Working...