私の問題は、次のスクリプトが一部の IRI で機能し、他のスクリプトでは機能しないことです。私の質問は、なぜこのように動作し、どのように解決するのかということです。文字セットに問題があると思いますが、ウィキペディアでは機能するため、推測にすぎません。
<?php
include('C:\xampp\htdocs\php\simple_html_dom.php');
$html = file_get_html('http://de.wikisource.org/wiki/Am_B%C3%A4chle');
//Titel
foreach($html->find('span#ws-title') as $f)
echo $f->plaintext;
//1 http://de.wikisource.org/wiki/7._August_1929 OK
//2 http://de.wikisource.org/wiki/%E2%80%99s_ist_Krieg! -
//3 http://de.wikisource.org/wiki/Am_B%C3%A4chle -
//4 http://de.wikipedia.org/wiki/Guillaume-Aff%C3%A4re OK
//5 http://de.wikisource.org/wiki/Solidit%C3%A4t -
?>
5 つの IRI がその例です。最後の 3 つの IRI には %C3%A4 が含まれています。これは「ä」ですが、ウィキペディアの 1 つだけが機能します。2. IRI には %E2%80%99 が含まれています。これは " ' " です - 動作しません。
しかし、wikisource からの最初の IRI は機能します。ä、ö、... を含まないウィキソースのすべての IRI についても同様です。
動作しない場合、次の警告が表示されます。
警告: file_get_contents(http://de.wikisource.org/wiki/Solidit%C3%A4t): ストリームを開けませんでした: HTTP リクエストが失敗しました! HTTP/1.0 403 C:\xampp\htdocs\php\simple_html_dom.php 行 70 で禁止されています
致命的なエラー: 5 行目の C:\xampp\htdocs\php\frage.php の非オブジェクトに対するメンバー関数 find() の呼び出し
simple_html_dom.php の 70 行目を含む関数は次のようになります。
//65 function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT)
//66 {
//67 // We DO force the tags to be terminated.
//68 $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $defaultBRText);
//69 // For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done.
//70 $contents = file_get_contents($url, $use_include_path, $context, $offset);
//71 // Paperg - use our own mechanism for getting the contents as we want to control the timeout.
//72 // $contents = retrieve_url_contents($url);
//73 if (empty($contents))
//74 {
//75 return false;
//76 }
//77 // The second parameter can force the selectors to all be lowercase.
//78 $dom->load($contents, $lowercase, $stripRN);
//79 return $dom;
//80 }
ウィキペディアまたはウィキソースのすべての IRI に対してスクリプトを機能させる方法はありますか? (常に があるとは限らないことはわかっていますがspan#ws-title
、それは私の問題ではありません。)