【问题标题】:File_Get_Contents an Entire ArrayFile_Get_Contents 整个数组
【发布时间】:2012-09-23 11:41:54
【问题描述】:

我希望数组中的每个链接都有 file_get_contents。因此,我可以应用 preg_match 代码,然后匹配检测到的前 p 个标签中的所有前 20 个字符。

我的代码如下:

 $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;

【问题讨论】:

    标签: php file-get-contents


    【解决方案1】:

    您可以在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;
      }
    

    【讨论】:

      【解决方案2】:

      为什么不使用他们的 API?

      您仍然可以使用file_get_contents 来检索内容,但您可以决定更适合您需要的格式。

      他们的 API 记录得很好,请参阅:http://www.mediawiki.org/wiki/API:Main_page

      URL 会变成某种东西

      【讨论】:

        猜你喜欢
        • 2016-03-22
        • 1970-01-01
        • 1970-01-01
        • 2012-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-16
        • 2022-01-09
        相关资源
        最近更新 更多