Hi
I'm trying to write some code to sort of normalise filenames - to remove any strange characters, replaced accented characters with the non-accented equivalent, replace spaces with a dash etc
so far it's ok :
$string = "l'éléction .à nîmes c'est maïs **en españa. la ²&<'(-_)=$^*!:;,~#{[|`\^@]}¤?§%µ£¨+°>$££££ d'être là.jpg";
$bits = split('\.',$string);
$numBits = count($bits);
$str = "";
for($i=0;$i<($numBits-1);$i++){
$str .= $bits[$i];
}
$str = strtolower($str);
$rep_fr = array("à","â","ä","é","è","ë","ê","ï","î","ô","ö","ù","û","ç","ñ","l'","d'","s'","m'","t'","n'","c'"," ","--");
$rep_to = array("a","a","a","e","e","e","e","i","i","o","o","u","u","c","n", "" , "" , "" , "" , "" , "" , "" , "-","-");
for($i=0;$i<count($rep_fr);$i++){
$str = str_replace($rep_fr[$i],$rep_to[$i],$str);
}
$str = ereg_replace("[^A-Za-z0-9/-]", "", $str);
$last = ($numBits-1);
$ext = $bits[$last];
echo "<br>".$str.".".$ext;
but the string in the above example outputs like this :
election-a-nimes-est-mais-en-espana-la---etre-la.jpg
so what i need now is a way of replacing any multiple dashes with a single dash - how could i do that ?
or is there maybe a simpler way to go about this using less code ?
thanks