私はDOMDocument
、Webページから数ビットのテキストを取得し、それらを配列に配置するために使用しています。同じコードが別のサーバーで機能しますが、私のものでは機能しません。ループTrying to get property of non-object
の反復ごとに取得し、最後に配列が空のままになります。while
$html = file_get_contents("http://sugarkettle.site44.com/catering.html");
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);
libxml_clear_errors();
$meatPrices = array();
function fillArrayFromDOM($array,$type) {
global $doc;
$i = 0;
$label = 1;
$array = array();
while ($label <= 15):
$array[$i] = $doc->getElementById($type.$label)->textContent;
$i++;
$label++;
endwhile;
return $array;
}
fillArrayFromDOM($meatPrices,"meat");
echo var_dump($meatPrices);
これが機能するためのリンクです:http: //www.evintr.com/willtest.php
彼はGoDaddyサーバーを実行していて、私はローカルWAMP(2.2)サーバーを持っています。これが発生している理由を説明する可能性のある、提供できる構成オプションはありますか?または、問題はサーバー構成とは何の関係もありませんか?
どんな助けでも大歓迎です。前もって感謝します!
アップデート1-11/16/12
私のサーバーでテスト$meatPrices[1] = $doc->getElementById('meat1')->textContent;
しましたが、動作します。何らかの理由で、while
ループ内で同じ式(パラメーター内の変数を除くgetElementById
)がエラーをスローしますTrying to get property of non-object
。
アップデート2-11/17/12
私のWAMPサーバーはPHPバージョン5.3.13を実行しています。私の友人のサーバーはPHPバージョン5.3.6を実行しています。