0

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

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

    }
}

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

注意:fopen 在我的 PHP 中是开启的。

添加:

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

1 回答 1

0

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

此外,没有 PHP 功能write()

于 2012-04-20T11:02:31.983 回答