note 88292 added to function.strtoupper
| From: | chris at table4 dot com | Date: | Mon, 19 Jan 2009 15:31:08 +0000 |
| Subject: | note 88292 added to function.strtoupper | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149447@lists.php.net to get a copy of this message | ||
Simple function to change the case of your string and any accented html characters contained within
it.
Inspired by fullUpper(), by silent at gmx dot li... just a little bit more atomic.
<?php
function convertCase($str, $case = 'upper')
{ //yours, courtesy of table4.com :)
switch($case)
{
case "upper" :
default:
$str = strtoupper($str);
$pattern = '/&([A-Z])(UML|ACUTE|CIRC|TILDE|RING|';
$pattern .= 'ELIG|GRAVE|SLASH|HORN|CEDIL|TH);/e';
$replace =
"'&'.'\\1'.strtolower('\\2').';'"; //convert
the important bit back to lower
break;
case "lower" :
$str = strtolower($str);
break;
}
$str = preg_replace($pattern, $replace, $str);
return $str;
}
?>
Depending on what you are trying to achieve you would call like this:
<?php
//with entities...
$str = convertCase(htmlentities($str, ENT_QUOTES, "ISO-8859-1"));
?>
----
Server IP: 92.48.74.199
Probable Submitter: 217.34.32.90
----
Manual Page -- http://www.php.net/manual/en/function.strtoupper.php
Edit -- https://master.php.net/note/edit/88292
Del: integrated -- https://master.php.net/note/delete/88292/integrated
Del: useless -- https://master.php.net/note/delete/88292/useless
Del: bad code -- https://master.php.net/note/delete/88292/bad+code
Del: spam -- https://master.php.net/note/delete/88292/spam
Del: non-english -- https://master.php.net/note/delete/88292/non-english
Del: in docs -- https://master.php.net/note/delete/88292/in+docs
Del: other reasons-- https://master.php.net/note/delete/88292
Reject -- https://master.php.net/note/reject/88292
Search -- https://master.php.net/manage/user-notes.php