谷歌公关检查代码中的一个函数


a function from google pr check code

我是php的新手。为了提高它的技巧,我搜索了一些例子来练习它。现在,我找到了一个。

http://www.brightyoursite.com/blog/2010/06/01/use-php-to-get-google-page-rank/

但代码对我来说很难理解。

function StrToNum($Str, $Check, $Magic) {
        $Int32Unit = 4294967296; 
        $length = strlen($Str);
        for ($i = 0; $i < $length; $i++) {
            $Check *= $Magic;

            if ($Check >= $Int32Unit) {
                $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
                //if the check less than -2^31
                $Check = ($Check < -2147483648)? ($Check + $Int32Unit) : $Check;
            }
            $Check += ord($Str{$i});
        }
        return $Check;
    }

我不太明白。希望有人能帮我?

1、这条线路$Int32Unit = 4294967296; 有什么用途和意义

2,for循环做什么?这个函数有什么用。

如果不理解int,为什么要删除注释?那是

好:

    $Int32Unit = 4294967296;  // 2^32

所以这个数字是2^32。记住这一点。

        //If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),
        //  the result of converting to integer is undefined
        //  refer to http://www.php.net/manual/en/language.types.integer.php

现在,它检查我们是否会得到一个合理的答案,因为正如链接和评论中所写的那样,你不能有太大的数字来转换。。。。

也许你想在走路之前先跑?如果这个例子对你来说太复杂了,那么回到更简单的地方,直到你的知识有所提高,然后再回来

网络上有很多针对PHP初学者的教程,比如http://devzone.zend.com/article/627.

我不是想在这里听起来很刺耳,但这是一个学习PHP的奇怪例子,一个更通用的教程对你来说不是更有用处吗?。祝你学习好运,我也是这样学习的,这可能很艰难,但也很有收获。