php - zencart中的一个函数不知道是要做什么的?
巴扎黑
巴扎黑 2017-04-10 15:23:05
0
0
815
function GBcase($text, $case)
{
    $case = strtolower($case);
    if ($case != "upper" && $case != "lower" && $case != "ucwords" && $case != "ucfirst")
    {
        return "函数用法错误。 $case";
    }
    else
    {
        $ucfirst = 0;
        $ucwords = 0;
        $news    = "";
        $l       = strlen($text);
        $GB      = 0;
        $english = 0;

        $a = 0;
        while ($a < $l)
        {

            $ch = substr($text, $a, 1);
            if ($GB == 0 && ord($ch) >= HexDec("0x81"))
            {

                $GB      = 1;
                $english = 0;
                $news .= $ch;
                $ucwords = 0;

            }
            elseif ($GB == 1 && ord($ch) >= HexDec("0x40") && $english == 0)
            {
                $news .= "$ch";
                $ucwords = 0;
                $GB      = 0;

            }
            else
            {
                if ($case == "upper")
                {
                    $news .= strtoupper($ch);
                }
                elseif ($case == "lower")
                {
                    $news .= strtolower($ch);
                }
                elseif ($case == "ucwords")
                {
                    if ($ucwords == 0)
                    {
                        $news .= strtoupper($ch);
                    }
                    else
                    {
                        $news .= strtolower($ch);
                    }
                    $ucwords = 1;
                }
                elseif ($case == "ucfirst")
                {
                    if ($ucfirst == 0)
                    {
                        $news .= strtoupper($ch);
                        $ucfirst = 1;
                    }
                    else
                    {
                        $news .= strtolower($ch);
                        $ucfirst = 1;
                    }
                }
                else
                {
                    $news .= $ch;
                }
                if ($ch == " " || $ch == "\n")
                {
                    $ucwords = 0;
                }
                $english = 1;
                $GB      = 0;

            }

            $a++;

        } // END OF while
        return $news;
    } // end else
}

这是zencart中文版中,中文版补充的一个函数,一个用例就是对$sql查询语句进行转换,如GBcase($sql,'lower'),这里要对$sql要做的就是根据$page/$size/$sql/$rows进行分页,如果要进行大小写转换直接用函数不就行了,我对ASCII编码这些也不是很懂,所以看不太懂这个。

巴扎黑
巴扎黑

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template