Exploding text form lines into an array
<p>I have a script that pulls in the Google Pagerank for inputted URLs.</p>

<p>I have tried editing the script so that instead of only being able to put 3 urls in you can paste a list of URL's in.</p>

<p>Unfortuantly when I past some URL's in it just puts them next to each other and doesn't display the Pagerank.</p>

<p>If you want to test it and see you can find it here: <a href="http://php-playground.co.cc/testdir/pagerank.php" rel="nofollow">http://php-playground.co.cc/testdir/pagerank.php</a></p>

<p>(people have been reporting a virus on the URL but its only because its a co.cc domain, do not click if you are worried :)</p>

<p>Here is the code:</p>

<pre><code>&lt;?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";
?&gt;
&lt;?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)&lt;br /&gt;\n";
    } else {
    $out = "GET /tbr?client=navclient-    auto&amp;ch=".CheckHash(HashURL($url))."&amp;features=Rank&amp;q=info:".$url."&amp;num=100&amp;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 &lt; $length; $i++) {
    $Check *= $Magic;
    if ($Check &gt;= $Int32Unit) {
        $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
        $Check = ($Check &lt; -2147483648)? ($Check + $Int32Unit) : $Check;
    }
    $Check += ord($Str{$i});
}
return $Check;
}

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

function CheckHash($Hashnum) {
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length - 1; $i &gt;= 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 &gt;&gt;= 1;
    }
}
return '7'.$CheckByte.$HashStr;
}
// Google PR Finder END



?&gt;

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

&lt;style type="text/css"&gt;
&lt;!--
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;}
--&gt;
&lt;/style&gt;&lt;/head&gt;
&lt;body&gt;

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