note 100673 deleted from function.ucwords by danbrown
| From: | danbrown@php.net | Date: | Fri, 29 Oct 2010 11:41:00 +0000 |
| Subject: | note 100673 deleted from function.ucwords by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173595@lists.php.net to get a copy of this message | ||
Note Submitter: Freddi
----
Here is a function that make the words prettier:
<?
function correct_words($s)
{
$a = explode(" ", $s);
foreach($a as $id => $t)
{
$low = false;
for($i = 0, $strlen = mb_strlen($t); $i <= $strlen; $i++)
{
if($low)
{
$t[$i] = mb_strtolower($t[$i]);
}
if(mb_ereg_match("[A-Z]", $t[$i]))
{
$low = true;
}
}
$a[$id] = $t;
}
foreach($a as $x)
{
$r .= $x . " ";
}
return(trim($r));
}
echo(correct_words("BIGWORD Correct Word smallword"));
?>
Output:
Bigword Correct Word smallword