更新されたコード
<?php
#header( "Content-Type: application/xml" );
function doLoop($arr = array())
{
global $newsStory;
foreach( $arr as $r )
{
//check if we're dealing with an array (multiple links)
if ( is_array($r) === true )
{
//loop through the array and work with each link
foreach ( $r as $link_)
//check if link is an array
if ( is_array($link_) ){doLoop($link_); continue;}
// //end of third dimension array found
## gets url from database as outlined above.
$xmlUrl = $link_;
#Loads the url above into XML
$ConvertToXml = simplexml_load_file($xmlUrl);
# -> Setup XML
$newsStory[] = $ConvertToXml->channel->item;
}//end of loop
continue;//move on
}//end of is array
//if we get here, we know that only $r is not an array, just a value, so:
## gets url from database as outlined above.
$xmlUrl = $r;
#Loads the url above into XML
#$ConvertToXml = simplexml_load_file($xmlUrl);
# -> Setup XML
#$newsStory[] = $ConvertToXml->channel->item;
$newsStory[] = $r;
print_r($newsStory);
}//end of function
## Loop through results from mysql
try{
#connection string
// $dbconn = new PDO('mysql:host=localhost;port=3306;dbname=thedb',array(PDO::ATTR_PERSISTENT => true));
$dbconn = new PDO('mysql:host=localhost;port=3306;dbname=thedb','root','toshiba1',array(PDO::ATTR_PERSISTENT => true));
$q = $dbconn->prepare("SELECT FW_ArtSrcLink FROM FW_ArtSrc WHERE OneSet=1 and leagID=20");
#call stored proc
$q->execute();
#get the rows into an array
$result = $q->fetchAll();
$newsStory = array();
doLoop($result);
# -----> Load News Stories
for($i = 0;$i<sizeof($newsStory); $i++){
//print_r($newsStory);
echo "<a href='".$newsStory[$i]->link."'>".$newsStory[$i]->title."</a><br />";
echo $newsStory[$i]->description;
echo '<hr>';
} // for()
} // try
catch(Exception $e){
$errorPg='errors/fanwire_loop.php';
$pageDateOfError = $e->getMessage().'on:'.'aggregate_looping.php'.' on '.date('l jS \of F Y h:i:s A'); # inc. details of error
file_put_contents($errorPg,$pageDateOfError, FILE_APPEND | LOCK_EX);
} // catch
?>
print_r() の出力:
print_r() からの別の出力例: