2013-08-28 2 views
0

하나 이상의 피드를 저장할 수 있도록 변수를 배열로 바꾸고 싶습니다. 내가 배열로로드하려면이 옵션을 변경할 수있는 방법변수 피드를 배열로 변환하는 방법은 무엇입니까?

<?php 
error_reporting(0); 

$feed_lifehacker_full = simplexml_load_file('http://feeds.gawker.com/lifehacker/full'); 

$xml = $feed_lifehacker_full; 
//print_r($xml); 

foreach ($xml->channel->item as $node){ 

$title = $node->title; 
$link = $node->link; 
$link = explode('/', $link); 
$link = $link[8]; 
$url = $node->url; 
$description = $node->description; 
$pubDate = $node->pubDate; 
preg_match_all('#(http://img[^\s]+(?=\.(jpe?g|png|gif)))#i', $description[0], $images); 
$images = $images[0][1] . '.jpg'; 
if($images == '.jpg'){ 

    //uncomment to show youtube articles 
    //$images = "http://placehold.it/640x360"; 
    //echo "<a href='page2.php?a=$link' title='$title'><img src='$images' /></a><br>"; 
} else { 
    //article image 
    $images . '<br>'; 
    echo "<a href='page2.php?a=$link' title='$title'><img src='$images' /></a><br>"; 
} 


} 

,

$feed_lifehacker_full = simplexml_load_file('http://feeds.gawker.com/lifehacker/full'); 

$xml = $feed_lifehacker_full; 

스크립트는 단지 RSS 피드의 이미지를 수집하고 당신이 더 많은 작업을 수행 할 수있는 방법을 볼 경우, 페이지에 연결됩니다 효율적으로는 JSON로 주어진 결과를 인코딩 할 수

답변

0

말을 자유롭게하고이를 디코딩하여 당신에게 배열을 반환합니다

$xml = simplexml_load_string($xmlstring); 
$json = json_encode($xml); 
$array = json_decode($json, TRUE); 
관련 문제