将文本形式线爆炸成数组

时间:2012-04-12 12:37:10

标签: php

我有一个脚本可以在Google Pagerank中输入输入的网址。

我已经尝试过编辑脚本,这样您就可以粘贴一个URL列表,而不是只能放入3个URL。

当我通过其中的一些URL时,只是将它们放在一起并且不显示Pagerank。

如果您想测试它并看到您可以在此处找到它:http://php-playground.co.cc/testdir/pagerank.php

(人们一直在报告网址上的病毒,但仅因为它是一个co.cc域名,如果您担心,请不要点击:)

以下是代码:

<?php
//If the form was submitted
if(isset($_GET['url[]'])){
    //Put every new line as a new entry in the array
    $url = explode("\n",trim($_POST["url[]"]));
        }

        echo "$url";
?>
<?php
function fetch_google_page_rank($url) {
$url = strstr($url,"http://")? $url:"http://".$url;
$fp = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
    } else {
    $out = "GET /tbr?client=navclient-    auto&ch=".CheckHash(HashURL($url))."&features=Rank&q=info:".$url."&num=100&filter=0   HTTP/1.1\r\n";
    $out .= "Host: toolbarqueries.google.com\r\n";
    $out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP   5.1)\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);

    while (!feof($fp)) {
        $data = fgets($fp, 128);
        $pos = strpos($data, "Rank_");
    if($pos === false){} else{
            $pagerank = substr($data, $pos + 9);
        }
    }
    fclose($fp);
    return (int)$pagerank;
}
}

function StrToNum($Str, $Check, $Magic) {
$Int32Unit = 4294967296; // 2^32
$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
    $Check *= $Magic;
    if ($Check >= $Int32Unit) {
        $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
        $Check = ($Check < -2147483648)? ($Check + $Int32Unit) : $Check;
    }
    $Check += ord($Str{$i});
}
return $Check;
}

function HashURL($String) {
$Check1 = StrToNum($String, 0x1505, 0x21);
$Check2 = StrToNum($String, 0, 0x1003F);
$Check1 >>= 2;
$Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
$Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
$Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
$T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) << 2 ) | ($Check2 & 0xF0F );
$T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 &    0xF0F0000 );
return ($T1 | $T2);
}

function CheckHash($Hashnum) {
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length - 1; $i >= 0; $i --) {
    $Re = $HashStr{$i};
    if (1 === ($Flag % 2)) {
        $Re += $Re;
        $Re = (int)($Re / 10) + ($Re % 10);
    }
    $CheckByte += $Re;
    $Flag ++;
}
$CheckByte %= 10;
if (0!== $CheckByte) {
    $CheckByte = 10 - $CheckByte;
    if (1 === ($Flag % 2) ) {
        if (1 === ($CheckByte % 2)) {
            $CheckByte += 9;
        }
        $CheckByte >>= 1;
    }
}
return '7'.$CheckByte.$HashStr;
}
// Google PR Finder END



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GET Google PR</title>

<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Geneva, sans-serif;
font-size: 11px;
color: #333;
}
body {
margin-left: 20px;
margin-top: 20px;
}
pre{ font-size:15px;}
-->
</style></head>
<body>

<h2>Google PR</h2>
<p>Enter your URLs </p>
<form action="" method="POST">
<p>
<textarea name="url[]" rows="10" cols="50"></textarea>
<!--<input name="url[]" type="text" id="url[]" value="http://" size="80" /><br />
<input name="url[]" type="text" id="url[]" value="http://" size="80" /><br />
<input name="url[]" type="text" id="url[]" value="http://" size="80" /><br />-->
</p>
<p><input name="findpr" type="submit" value="Find Google PageRank" />
<br />
<br />
</p>
</form>
<table>
<pre>
<?php
if(isset($_POST['findpr']))
{
foreach($_POST['url'] as $key => $url)
{
    if( $_POST['url'][$key]!="http://")
    echo "<td><b>PR:</td><td>" .  fetch_google_page_rank($_POST['url'][$key]) .     " </td><td></b>&raquo;</td><td>" . $_POST['url'][$key]."</td></tr><br />";
}
}
?>
</pre>
</table>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

固定代码:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
function fetch_google_page_rank($url) {
$url = strstr($url,"http://")? $url:"http://".$url;
$fp = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
    } else {
    $out = "GET /tbr?client=navclient-auto&ch=".CheckHash(HashURL($url))."&features=Rank&q=info:".$url."&num=100&filter=0   HTTP/1.1\r\n";
    $out .= "Host: toolbarqueries.google.com\r\n";
    $out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP   5.1)\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);

    while (!feof($fp)) {
        $data = fgets($fp, 128);
        $pos = strpos($data, "Rank_");
    if($pos === false){} else{
            $pagerank = substr($data, $pos + 9);
        }
    }
    fclose($fp);
    return (int)$pagerank;
}
}

function StrToNum($Str, $Check, $Magic) {
$Int32Unit = 4294967296; // 2^32
$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
    $Check *= $Magic;
    if ($Check >= $Int32Unit) {
        $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
        $Check = ($Check < -2147483648)? ($Check + $Int32Unit) : $Check;
    }
    $Check += ord($Str{$i});
}
return $Check;
}

function HashURL($String) {
$Check1 = StrToNum($String, 0x1505, 0x21);
$Check2 = StrToNum($String, 0, 0x1003F);
$Check1 >>= 2;
$Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
$Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
$Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
$T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) << 2 ) | ($Check2 & 0xF0F );
$T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 &    0xF0F0000 );
return ($T1 | $T2);
}

function CheckHash($Hashnum) {
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length - 1; $i >= 0; $i --) {
    $Re = $HashStr{$i};
    if (1 === ($Flag % 2)) {
        $Re += $Re;
        $Re = (int)($Re / 10) + ($Re % 10);
    }
    $CheckByte += $Re;
    $Flag ++;
}
$CheckByte %= 10;
if (0!== $CheckByte) {
    $CheckByte = 10 - $CheckByte;
    if (1 === ($Flag % 2) ) {
        if (1 === ($CheckByte % 2)) {
            $CheckByte += 9;
        }
        $CheckByte >>= 1;
    }
}
return '7'.$CheckByte.$HashStr;
}
// Google PR Finder END



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GET Google PR</title>

<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Geneva, sans-serif;
font-size: 11px;
color: #333;
}
body {
margin-left: 20px;
margin-top: 20px;
}
pre{ font-size:15px;}
-->
</style></head>
<body>

<h2>Google PR</h2>
<p>Enter your URLs </p>
<form action="" method="POST">
<p>
<textarea name="url" rows="10" cols="50"></textarea>
<!--<input name="url[]" type="text" id="url[]" value="http://" size="80" /><br />
<input name="url[]" type="text" id="url[]" value="http://" size="80" /><br />
<input name="url[]" type="text" id="url[]" value="http://" size="80" /><br />-->
</p>
<p><input name="findpr" type="submit" value="Find Google PageRank" />
<br />
<br />
</p>
</form>
<table>
<pre>
<?php

if(isset($_POST['findpr']))
{
$url = explode("\n",$_POST["url"]);
foreach($url as $key => $url_l)
{
$url_l=trim($url_l);
    if( $url_l!="http://")
    echo "<td><b>PR:</td><td>" .  fetch_google_page_rank($url_l) .     " </td><td></b>&raquo;</td><td>" . $url_l."</td></tr><br />";
}
}
?>
</pre>
</table>
</body>
</html>