Php 文件获取整个数组的内容

Php 文件获取整个数组的内容,php,file-get-contents,Php,File Get Contents,我希望在数组中的每个链接上都有文件内容。因此,我可以应用preg_匹配代码,然后匹配检测到的第一个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(", " , $l

我希望在数组中的每个链接上都有文件内容。因此,我可以应用preg_匹配代码,然后匹配检测到的第一个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;

您可以在文件内容中一次使用一个url。合并链接将不起作用,相反,您需要循环每个链接并获取内容

  $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;
  }
为什么不使用他们的API呢

您仍然可以使用file\u get\u内容来检索内容,但是您可以决定更适合您需要的格式

他们的API有很好的文档记录,请参见:

URL将转换为