note 13933 added to function.ucwords.php

From: Date: Tue, 10 Jul 2001 21:22:34 +0000
Subject: note 13933 added to function.ucwords.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-15181@lists.php.net to get a copy of this message
This is basically the same as Jim Thome's script above but it tests for numbers also. So if you have 3rd it won't end up 3Rd. function ucase_words($txt) { $i = 0; $txt = strtolower($txt); while ($i < strlen($txt)) { if (ord(substr($txt, $i, 1)) > 96 && ord(substr($txt, $i, 1)) < 123) // any lower case letter { if ($i == 0)//first letter should be upper case { $newtxt .= strtoupper(substr($txt, $i, 1)); } else {//check for preceding letter or number, so things like 3rd wont be 3Rd if ((ord(substr($txt, $i - 1, 1)) > 96 && ord(substr($txt, $i - 1 , 1)) < 123) || (ord(substr($txt, $i - 1, 1)) > 47 && ord(substr($txt, $i - 1, 1)) < 58)) { $newtxt .= substr($txt, $i, 1); } else { $newtxt .= strtoupper(substr($txt, $i, 1)); } } } else { $newtxt .= substr($txt, $i, 1); } $i++; } return($newtxt); } Paul Paul@webkromatic.com http://www.php.net/manual/en/function.ucwords.php

« previous php.notes (#15181) next »