1

配列内のすべてのリンクに file_get_contents が必要です。したがって、検出された最初の p タグの最初の 20 文字すべてに一致する preg_match コードを適用できます。

私のコードは以下です:

 $links = array(0 => "http://en.wikipedia.org/wiki/The_Big_Bang_Theory", 1=>  "http://en.wikipedia.org/wiki/Fantastic_Four");
   print_r($links);
  $link = implode(", " , $links);
  $html = file_get_contents($link);

  preg_match('%(<p[^>]*>.*?</p>)%i', $html, $re);
  $res = get_custom_excerpt($re[1]);
  echo $res;
4

2 に答える 2

0

では一度に 1 つの URL を使用できますfile_get_contents。リンクを組み合わせても機能しません。代わりに、各リンクをループしてコンテンツを取得する必要があります。

  $links = array(0 => "http://en.wikipedia.org/wiki/The_Big_Bang_Theory", 1=>  "http://en.wikipedia.org/wiki/Fantastic_Four");
  print_r($links);

  foreach($links as $link){
    $html = file_get_contents($link);
    preg_match('%(<p[^>]*>.*?</p>)%i', $html, $re);
    $res = get_custom_excerpt($re[1]);
    echo $res;
  }
于 2012-09-23T11:48:04.533 に答える
0

なぜ彼らのAPIを使わないのですか?

コンテンツを取得するために引き続き使用できfile_get_contentsますが、ニーズにより適した形式を決定できます。

彼らの API は非常によく文書化されています。http ://www.mediawiki.org/wiki/API:Main_page をご覧ください。

URLは何かに変わる

于 2012-09-23T11:50:20.640 に答える