You are here: Folder Name Function « PHP Programming Language « IT news, forums, messages
Folder Name Function

Posted by frizzle on 11/16/56 11:28

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:] ]","",$foldername);
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_replacements =
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($special_chars, $special_replacements,
$foldername);
//erases all NON-alfanumerics
$foldername = ereg_replace("[^[:alnum:] ]","",$foldername);
// take out repetative spaces:
$foldername = preg_replace('/\s\s+/', ' ', $foldername);
$foldername = preg_replace('/\s/', '_', $foldername);
$foldername = strtolower($foldername);
if ($foldername == ""){$foldername = "untitled";}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация