次のような形式の RSS フィードがあります。
<item>
<posturl>mysite.com/abc.html</posturl>
<imagepath>123.jpg</imagepath>
</item>
<item>
<posturl>mysite.com/def.html</posturl>
<imagepath>456.jpg</imagepath>
</item>
<item>
<posturl>mysite.com/ghi.html</posturl>
<imagepath>789.jpg</imagepath>
</item>
上記の両方の値を抽出するスクリプトがあります。値の 1 つを抽出し、次のようなコードを使用して HTML コードを作成できます。
<?php
$xml = simplexml_load_file('http://myrssfeed.com');
$imgs = $xml->xpath('//imagepath');
echo '<ul>';
foreach($imgs as $output1) {
echo '<li><img src="' . $output1 . '" ></li>';
}
echo '</ul>';
?>
ここの人々からのすべての助けのおかげで、これは魔法のように機能します。しかし、次のようなものを読むには、その2 番目のエコー行を展開する必要があります。
echo '<li><a href="' . $output2 . '"><img src="' . $output1 . '" ></a></li>';
$output1 と同じアイテム内で $output2 = posturl を抽出する方法について助けが必要です。
基本的に、画像をリンクとして表示する必要があります... imagepath と posturl の両方が item 内の要素です。
どうもありがとう。