note 41923 added to function.substr
| From: | flobi at flobi dot com | Date: | Mon, 26 Apr 2004 16:54:29 +0000 |
| Subject: | note 41923 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68824@lists.php.net to get a copy of this message | ||
Perhaps this one should be built in?
<?
function ucwordsmc($sourcestring) {
$sourcestring = ucwords($sourcestring);
$returnstring = "";
for($t=0;$t<strlen($sourcestring);$t++) {
$checkchar = substr($sourcestring, $t, 1);
if (substr($sourcestring, $t, 2) === "Mc") {
$returnstring .= substr($sourcestring, $t, 2);
$t += 2;
$returnstring .= strtoupper(substr($sourcestring, $t, 1));
} else {
$returnstring .= $checkchar;
}
}
return $returnstring;
}
echo ucwordsmc("mcdonald's"); // Returns "McDonald's"
?>
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41923
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41923&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41923&report=yes
Search -- http://master.php.net/manage/user-notes.php