大小写转化

function str_toupper($str)
{
    if(!is_string($str))
    {
        return $str;
    }
    $strOut = '';
    $strArr = str_split($str,1);
    foreach($strArr as $val)
    {
        if(ord($val) >= ord('a') && ord($val) <= ord('z'))
        {   
            $strAscii = ord($val);
            $strAscii += ord('A') - ord('a'); 
            $val = chr($strAscii);
        }
        $strOut .= $val;
    }
    return $strOut;
}
function str_tolower($str)
{
    if(!is_string($str))
    {
        return $str;
    }
    $strOut = '';
    $strArr = str_split($str,1);
    foreach($strArr as $val)
    {
        if(ord($val) >= ord('A') && ord($val) <= ord('Z'))
        {   
            $strAscii = ord($val);
            $strAscii += ord('a') - ord('A'); 
            $val = chr($strAscii);
        }
        $strOut .= $val;
    }
    return $strOut;
}

你可能感兴趣的:(大小写转化)