Home  >  Q&A  >  body text

php - zencart中的一个函数不知道是要做什么的?

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编码这些也不是很懂,所以看不太懂这个。

巴扎黑巴扎黑2768 days ago773

reply all(0)I'll reply

No reply
  • Cancelreply