note 78303 deleted from function.strtoupper by sobak

From: Date: Thu, 17 Nov 2016 06:31:05 +0000
Subject: note 78303 deleted from function.strtoupper by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207132@lists.php.net to get a copy of this message
Note Submitter: xguimax at gmail dot com ---- Portuguese version of String Capitalize in PHP. function strProper($str) { $noUp = array('um','uma','o','a','de','do','da','em'); $str = trim($str); $str = strtoupper($str[0]) . strtolower(substr($str, 1)); for($i=1; $i<strlen($str)-1; ++$i) { if($str[$i]==' ') { for($j=$i+1; $j<strlen($str) && $str[$j]!=' '; ++$j); //find next space $size = $j-$i-1; $shortWord = false; if($size<=3) { $theWord = substr($str,$i+1,$size); for($j=0; $j<count($noUp) && !$shortWord; ++$j) if($theWord==$noUp[$j]) $shortWord = true; } if( !$shortWord ) $str = substr($str, 0, $i+1) . strtoupper($str[$i+1]) . substr($str, $i+2); } $i+=$size; } return $str; }

« previous php.notes (#207132) next »