当前位置: 动力学知识库 > 问答 > 编程问答 >

php - require_once() breaking array of urls that should generate OpenGraph tags?

问题描述:

Having trouble with this code, wondering if I'm trying to achieve something impossible. I'm using the OpenGraph PHP library

I want to fetch an array of urls, send them each through OpenGraph.php and then echo out a few Open Graph tags from that url.

The require_once() function seems to break the array, because I think it narrows the retrieval of $urls[$i] to OpenGraph.php? Am I going about this the wrong way?

<?php

$urls = array();

$paras = array();

$c=0;

foreach($_POST as $variable){

if($i==1){

array_push($urls,$variable);

$i++;

}else{

array_push($paras,$variable);

$i=1;

}

$c++;

};

echo'<table>';

for($i=0;$i<$c;$i++){

require_once('OpenGraph.php');

$graph = OpenGraph::fetch("$urls[$i]");

echo $graph->title;

echo'<tr><td>'.$paras[$i].'</td></tr>'

}

echo'</table>';

?>

Thanks!

EDIT

The require_once() function was not the problem and it certainly didn't need to be in the loop. The issue was running the file on my localhost PHP was not correctly configured for the task. Moving it onto server that was configured correctly fixed it.

网友答案:

The require_once() function was not the problem and it certainly didn't need to be in the loop. The issue was running the file on my localhost PHP was not correctly configured for the task. Moving it onto a proper server that was configured correctly fixed it.

分享给朋友:
您可能感兴趣的文章:
随机阅读: