note 29618 modified in function.explode by aidan
| From: | aidan@php.net | Date: | Sun, 27 Jun 2004 14:27:59 +0000 |
| Subject: | note 29618 modified in function.explode by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71928@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 !
<?php
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 ...).
--was--
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://php.net/manual/en/function.explode.php