0

我现在已经完成了一个脚本,并且所有内容都已调试并且可以正常工作,除了最后一个障碍。此脚本获取银行网站上的相关信息,获取该数据并使用它来填充模板,然后将其全部发布到 Wordpress - 但我收到错误,因为 file_get_contents 函数无法从数组中获取每个 url。

我已经对数组进行了 var_dumped,所有的 URL 都在 [0] 键中,所以这就是我尝试过的。

  • 主数据是脚本使用的抓取 URL 源
  • urlscrape_array 是 URL 的集合

    $master_data = file_get_contents($urlscrape_array[0]);

当我使用如下所示的 URL 运行脚本时,它每次都运行良好;

   $master_data = file_get_contents("http://www.somesite/somepage.html");

这是我尝试使用第一个示例时遇到的错误'

   Warning: file_get_contents() expects parameter 1 to be string, array given    in /home3/path/public_html/mysite.com/boise_project/scriptmainpage.php on line 13

按照这里的要求是 $urlscrape_array[0] 上的 var_dump 示例

  array(504) { [0]=> string(56) "http://www.somepage.com/somepage-3178.html" [1]=> string(54) "http://www.somepage.com/somepage-16.html" [2]=> string(56) "http://www.somepage.com/somepage-3202.html" [3]=> string(56) "http://www.somepage.com/somepage-4324.html" [4]=> string(56) "http://www.somepage.com/somepage-4777.html" [5]=> string(56) "http://www.somepage.com/somepage-5140.html" [6]=> string(56) "http://www.somepage.com/somepage-5220.html" [7]=> string(56) "http://www.somepage.com/somepage-9205.html" [8]=> string(56) "http://www.somepage.com/somepage-3251.html" [9]=> string(56) "http://www.somepage.com/somepage-3323.html" [10]=> string(56) "http://www.somepage.com/some-page-3797.html" [11]=> string(56) "http://www.somepage.com/some-page-4145.html" [12]=> string(56) "http://www.somepage.com/some-page-3191.html" [13]=> string(55) "http://www.somepage.com/some-page-329.html" [14]=> string(56) etc....


   Error as per the foreach statement provided by Uptown
   Warning: Invalid argument supplied for foreach() in /home3/bettyt45/public_html/bdbud.com/boise_project/boise-wordpress.php on line 12

无效的

print_r 结果如下;

    Array ( [0] => Array ( [0] => http://www.somesite.com/some-page-3178.html [1] => http://www.somesite.com/some-page-16.html [2] => http://www.somesite.com/some-page-3202.html [3] => http://www.somesite.com/some-page-4324.html [4] => http://www.somesite.com/some-page-4777.html [5] => http://www.somesite.com/some-page-5140.html [6] => http://www.somesite.com/some-page-5220.html [7] => http://www.somesite.com/some-page-9205.html [8] => http://www.somesite.com/some-page-3251.html [9] => http://www.somesite.com/some-page-3323.html [10] => http://www.somesite.com/some-page-3797.html [11] => http://www.somesite.com/some-page-4145.html [12] => http://www.somesite.com/some-page-3191.html [13] => http://www.somesite.com/some-page-329.html [14] => http://www.somesite.com/some-page-3341.html [15] => http://www.somesite.com/some-page-3758.html [16] => http://www.somesite.com/some-page-4180.html [17] => http://www.somesite.com/some-page-9014.html [18] => http://www.somesite.com/some-page-5987.html [19] => http://www.somesite.com/some-page-1542.html [20] => http://www.somesite.com/some-page-3004.html [21] => http://www.somesite.com/some-page-9034.html [22] => http://www.somesite.com/some-page-3385.html [23] => http://www.somesite.com/some-page-3435.html [24] => http://www.somesite.com/some-page-6389.html [25] => http://www.somesite.com/some-page-6992.html [26] => http://www.somesite.com/some-page-7051.html 

这是我用来创建上述数组的代码;

       $urlscrape_data = file_get_contents('http://www.mysite.com/boise_project/boise-urls.htm');
       preg_match_all('~http\:\/\/www.somesite.com\/some\-page\-\d{1,4}?\.html~',   $urlscrape_data, $urlscrape_matches);

$urlscrape_array = $urlscrape_matches;

4

1 回答 1

0
foreach($urlscrape as $url){
 echo $url; //confirm url is changing
 $master_data = file_get_contents($url);
 echo $master_data;
}
于 2013-11-02T02:25:03.427 回答