note 41193 deleted from function.str-replace by bjori

From: Date: Sun, 26 Mar 2006 22:28:25 +0000
Subject: note 41193 deleted from function.str-replace by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106684@lists.php.net to get a copy of this message
Note Submitter: sonicavanger at copyleft dot com ---- This function was originally written to produce UNIX and Windows conform Filenames from DB :: Firstname, Lastname. <?php // --------------------------------------------------------- // function forceFilename($str, $spaceChar) // // convert $str to a UNIX/Windows-conform filename // a char for $spaceChar will replace the default whitespace '_' // note when using '.' internet exploer adds automatically "[1]" // for e.g. "This[1].is.a.filename.ext" in the save as dialog. // --------------------------------------------------------- function forceFilename($str, $spaceChar = '_') { $str=trim($str); $_str = ''; $i_max = strlen($str); for ($i=0; $i<strlen($str); $i++) { $ch = $str[$i]; switch ($ch) { case 'Ä': case 'Æ': $_str .= 'AE'; break; case 'ä': case 'æ': $_str .= 'ae'; break; case 'à': case 'á': case 'â': case 'ã': case 'å': $_str .= 'a'; break; case 'À': case 'Á': case 'Â': case 'Ã': case 'Å': $_str .= 'a'; break; case 'Ç': case 'ç': $_str .= 'c'; break; case 'è': case 'é': case 'ê': case 'ë': $_str .= 'e'; break; case 'È': case 'É': case 'Ê': case 'Ë': $_str .= 'E'; break; case 'Ì': case 'Í': case 'Î': case 'Ï': $_str .= 'I'; break; case 'ì': case 'í': case 'î': case 'ï': $_str .= 'i'; break; case 'Ñ': case 'ñ': $_str .= 'n'; break; case 'Ö': $_str .= 'OE'; break; case 'ö': $_str .= 'oe'; break; case 'Ò': case 'Ó': case 'Ô': case 'Õ': $_str .= 'O'; break; case 'ò': case 'ó': case 'ô': case 'õ': $_str .= 'i'; break; case 'ß': $_str .= 'ss'; break; case 'Ù': case 'Ú': case 'Û': $_str .= 'U'; break; case 'ù': case 'ú': case 'û': $_str .= 'u'; break; case 'Ü': $_str .= 'UE'; break; case 'ü': $_str .= 'ue'; break; case 'Ý': $_str .= 'Y'; break; case 'ý': case 'ÿ': $_str .= 'y'; break; case 'Ð': $_str .= 'D'; break; case ' ': $_str .= $spaceChar; break; case '/': case '\'': case '-': case ':': $_str .= '-'; break; default : if (ereg('[A-Za-z0-9\(\)]', $ch)) { $_str .= $ch; } break; } } $_str = str_replace("{$spaceChar}{$spaceChar}", "{$spaceChar}", $_str); $_str = str_replace("{$spaceChar}-", '-', $_str); $_str = str_replace("-{$spaceChar}", '-', $_str); return $_str; } ?>

« previous php.notes (#106684) next »