note 41173 added to function.ucfirst

From: Date: Thu, 01 Apr 2004 18:16:06 +0000
Subject: note 41173 added to function.ucfirst
Groups: php.notes 
Request: Send a blank email to php-notes+get-67481@lists.php.net to get a copy of this message
this is a advance ucfirst function, for upper especifics words, with config in array of seperator /** * @return string * @param string $str frase que passará pelo parce * @desc Pega uma frase e devolve a mesma com as palavras com suas * maiusculas obedecendo um criterio configurado no array $string_sep * * @since 2004-04-01 15:04 adicionado a variavel $tring_sep que é um * array contendo todos os separadores a serem usados */ function str_upper_lower($str) { /** * array contendo todos os separadores */ $string_sep=array(' ','-','/','_','.'); /** * coloca todas as palavras com letras minusculas */ $str=strtolower($str); /** * testa todos os separadores */ for ($i=0;$i<count($string_sep);$i++) { $sep=$string_sep[$i]; /** * separa a frase usando os separador atual */ $array_words = explode($sep, $str); /** * variavel que conterá o valor temporario */ $tmp_str = ''; $i2=0; foreach ($array_words as $word) { /** * se a quantidade de caracteres for maior que dois, ou se conter ponto, * devolve upper da primeira letra */ $tmp_str .=(strlen($word)>2 || strpos($word,'.')?ucfirst($word):$word); /** * não adiciona o separador no fim de strings */ if ($i2<count($array_words)-1) { $tmp_str .= $sep; } $i2++; } $str = $tmp_str; } return $str; } ---- Manual Page -- http://www.php.net/manual/en/function.ucfirst.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41173 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41173&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41173&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67481) next »