ConFoo Montreal 2026: Call for Papers

Voting

: min(zero, four)?
(Example: nine)

The Note You're Voting On

chris at table4 dot com
16 years ago
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"));

?>

<< Back to user notes page

To Top