开发者

a function from google pr check code

i am new to php. to improve the skill of it. i searched some examples to practice it. now,i found one.

http://www.brightyoursite开发者_开发技巧.com/blog/2010/06/01/use-php-to-get-google-page-rank/

but the code for me is hard to understand.

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;
    }

i don't understand it well. expect someon can help me?

1, what's the use and meaning of this line $Int32Unit = 4294967296;

2,what's the for loop do? what's the use of this function.


Why did you remove the comments if you don't understand the int? That's.....

Ok:

    $Int32Unit = 4294967296;  // 2^32

So that number is 2^32. remember that.

        //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

Now it checks if we are going to get a sane answer or not, because you can't have a too big a number to convert, as written in that link and that comment....


Maybe you are trying to run before you can walk? If this example is too complex for you, then step back to something simpler until your knowledge improves then come back to it.

The web has plenty of tutorials for PHP beginners, such as this http://devzone.zend.com/article/627.

I don't mean to sound harsh here, but that is a strange example to choose for learning PHP, wouldn't a more general tutorial be of more use to you?. Good luck with your learning, I learnt the same way, it can be tough but very rewarding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜