note 29618 added to function.explode
| From: | jasenko at get2net dot dk | Date: | Wed, 19 Feb 2003 12:42:35 +0000 |
| Subject: | note 29618 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44197@lists.php.net to get a copy of this message | ||
This is example of converting strings to proper case (as we know it from VB). It shows use of PHP
string functions explode(), substr() and trim() along with case converting functions.
It's quite simple !
function properCase($strIn)
{
$arrTmp = explode(" ", trim($strIn));
for($i=0; $i < count($arrTmp);$i++)
{
$firstLetter = substr($arrTmp[$i],0,1);
$rest = substr($arrTmp[$i],1,strlen($arrTmp[$i]));
$arrOut[$i] = strtoupper($firstLetter).strtolower($rest);
}
for($j=0; $j < count($arrOut); $j++)
$retVal .= $arrOut[$j]." ";
return trim($retVal);
}
Hope this can be usefull to someone (I know it was to me ...).
--
http://www.php.net/manual/en/function.explode.php
http://master.php.net/manage/user-notes.php?action=edit+29618
http://master.php.net/manage/user-notes.php?action=delete+29618
http://master.php.net/manage/user-notes.php?action=reject+29618