传递变量时出现奇怪的卷曲行为

时间:2013-12-22 06:56:13

标签: php curl

我正在使用php Curl功能

function file_get_contents_curl($runfile) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, 0);

        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_URL,$runfile);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);   
        $content = curl_exec ($ch);

        curl_close ($ch); 
        return $content;
  }

我称之为

$htmld = file_get_contents_curl('http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567050922&profile=cmpltPrfl&profileId=1921&app=sold');

它帮助我获取页面。但是当我使用像

这样的数组变量调用它时
$htmld = file_get_contents_curl($anchorData[1]);//$anchorData[1] contains the above url.

我确定将相同的url传递给该方法。我用

进行了测试
  

的print_r()

方法内部。但是使用包含相同url字符串的数组索引变量调用该方法不会加载任何内容。我有什么错误的想法?或者如果可能的话,一点点解释都会很明显。为了您的信息,我首先通过调用相同的curl方法来准备数组。

我的数组数据是:

Array ( [0] => http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567050922&profile=cmpltPrfl&profileId=1921&app=sold [1] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567050922&profile=cmpltPrfl&profileId=1921&app=sold' [2] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567128263&profile=cmpltPrfl&profileId=1921&app=sold' [3] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=123456111961&profile=cmpltPrfl&profileId=1921&app=sold' [4] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567132673&profile=cmpltPrfl&profileId=1921&app=sold' [5] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567138184&profile=cmpltPrfl&profileId=1921&app=sold' [6] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567135196&profile=cmpltPrfl&profileId=1921&app=sold' [7] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567045581&profile=cmpltPrfl&profileId=1921&app=sold' [8] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567012024&profile=cmpltPrfl&profileId=1921&app=sold' [9] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567132264&profile=cmpltPrfl&profileId=1921&app=sold' [10] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567008037&profile=cmpltPrfl&profileId=1921&app=sold' [11] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=123456063828&profile=cmpltPrfl&profileId=1921&app=sold' [12] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567028132&profile=cmpltPrfl&profileId=1921&app=sold' [13] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567032740&profile=cmpltPrfl&profileId=1921&app=sold' [14] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567105864&profile=cmpltPrfl&profileId=1921&app=sold' [15] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567028990&profile=cmpltPrfl&profileId=1921&app=sold' [16] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=100204360000&profile=cmpltPrfl&profileId=1921&app=sold' [17] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=123456200387&profile=cmpltPrfl&profileId=1921&app=sold' [18] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=123456167676&profile=cmpltPrfl&profileId=1921&app=sold' [19] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234082710000&profile=cmpltPrfl&profileId=1921&app=sold' [20] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=123456245846&profile=cmpltPrfl&profileId=1921&app=sold' [21] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567055654&profile=cmpltPrfl&profileId=1921&app=sold' [22] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=123456228379&profile=cmpltPrfl&profileId=1921&app=sold' [23] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567093798&profile=cmpltPrfl&profileId=1921&app=sold' [24] => 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=123456254784&profile=cmpltPrfl&profileId=1921&app=sold' ) 

1 个答案:

答案 0 :(得分:0)

$anchorData = array();

    function file_get_contents_curl($runfile) {
       $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $runfile);

        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_URL,$runfile);

        $content = curl_exec ($ch);

        curl_close ($ch); 
        return $content;
    }

    $anchorData[0] = 'http://www.ic.gc.ca/app/ccc/srch/nvgt.do?lang=eng&prtl=1&sbPrtl=&estblmntNo=234567050922&profile=cmpltPrfl&profileId=1921&app=sold';
    $htmld = file_get_contents_curl($anchorData[0]);
    print_r($htmld);

这是我测试过的一段代码,它的运行只是检查出来。