链接提取脚本是PHP中的套管问题

时间:2012-04-20 10:59:50

标签: php fopen

我创建了一个循环来从谷歌中提取特定链接。但是当我运行这个脚本时,它正在创建没有任何链接的空文件。

for ($n=0;$n<500;$n+=10) 
{
$country = $_GET['country']; 
    // Country Changing array to scan through different countries.
        $google = array (
            "default" => array("google.com" , "countryUS"),
            "NZ" => array("google.co.nz" , "countryNZ"),
            "UK" => array("google.co.uk" , "countryUK|countryGB"),
            "AU" => array("google.com.au" , "countryAU")        
        );
// Variables for fopen
    $URL = 'www.'.$google[$country][0];
    $PORT = "80";
    $TIMEOUT = 30;
    $Q = $_GET['query'];


// Google String
$GET = '/search?q='.urlencode($Q).'&hl=en&cr='.$google[$country][1].'&tbs=ctr:'.$google[$country][1].'&start='.$n.'&sa=N';
    $fp = fsockopen($URL, $PORT, $errno, $errstr, $TIMEOUT);
    if (!$fp) 
    {
        echo "Error connecting to {$URL}<br>\n";
    } else 
    {
        $out = "GET $GET HTTP/1.1\r\n";
        $out .= "Host: $URL\r\n";
        $out .= "Connection: Close\r\n\r\n";
        fwrite($fp, $out);
        $buffer = '';
        while (!feof($fp)) 
        {
            $buffer .= fgets($fp, 128);
        }
        fclose($fp);
        write($SITEs, filter($buffer));

    }
}

如果我做错了,请告诉我。

注意:我的PHP中 fopen为ON。

添加:

    function write($A, $B) {
        @touch($A);
        $C = fopen($A, 'a');
        fwrite($C, $B);
        fclose($C);
    }

1 个答案:

答案 0 :(得分:0)

您还没有打开要写入的文件!

此外,还没有PHP函数write()