2017-11-07 4 views
0

는이 코드를 가지고 있지만 나는 미디어워드 프레스 피드 RSS XML - PHP 미디어

누군가가 나를 도울 수 받기 어떻게 몰라? 내 웹 사이트에 게시물의 이미지를 표시해야합니다

워드 프레스에 대한 내 PHP와 XML 아래

PHP 피드

$html = ""; 
$url = "https://intercambioemgalway.com.br/feed/"; 
$xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA); 

for ($i = 0; $i < 5; $i++){ 
    $img = $xml->channel->item->media; 
    $html .= "$img"; 
} 
echo $html; 

XML

<item> 
<title>Qual escola vou estudar?</title> 
<link>https://intercambioemgalway.com.br/2017/09/11/qual-escola-estudar/</link> 
<comments>https://intercambioemgalway.com.br/2017/09/11/qual-escola-estudar/#respond</comments> 
<pubDate>Mon, 11 Sep 2017 17:36:59 +0000</pubDate> 
<dc:creator><![CDATA[admin]]></dc:creator> 
<category><![CDATA[Meu intercâmbio]]></category> 

<guid isPermaLink="false">https://intercambioemgalway.com.br/?p=179</guid> 
<description><![CDATA[<p>Hoje vou contar um pouquinho da escola que vou estudar em Galway, a Atlantic Language.</p>]]></description> 
<wfw:commentRss>https://intercambioemgalway.com.br/2017/09/11/qual-escola-estudar/feed/</wfw:commentRss> 
<slash:comments>0</slash:comments> 
<media:content url="https://intercambioemgalway.com.br/wp-content/uploads/2017/09/Untitled-1.jpg" type="image/jpeg" medium="image" width="900" height="600"> 
    <media:title type="plain"> 
     <![CDATA[atlantic-language-galway]]> 
    </media:title> 
    <media:thumbnail url="https://intercambioemgalway.com.br/wp-content/uploads/2017/09/Untitled-1-150x150.jpg" width="150" height="150" /> 
    <media:description type="plain"> 
     <![CDATA[]]> 
    </media:description> 
    <media:copyright> 
     admin 
    </media:copyright> 
</media:content> 

+0

추가 된 언어 형식의 태그 –

답변

0

$itemSimpleXMLElement입니다.

이제 http://search.yahoo.com/mrss/ 네임 스페이스를 사용하여 자식을 반복 할 수 있으며 attributes에 액세스 할 수 있습니다. 예를 들어

:

foreach($xml->channel->item as $item) { 
    foreach($item->children("http://search.yahoo.com/mrss/") as $media) { 
     $img = (string)$media->attributes()->url; 
    } 
} 
+0

그것은, 감사했다 !!!!!!!!!! –

+0

코드를 약간 업데이트하고'를 제거했습니다. '$ img' 변수 끝에 "
"이 있습니다. –