スクリプトはすべて完了しており、すべてがデバッグされており、最後のハードルを除いて機能しています。このスクリプトは、銀行の Web サイトの関連情報を取得し、そのデータを使用してテンプレートに入力し、すべて 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;