English 中文(简体)
我如何显示来自此 XML 种子的图像?
原标题:How do I display images from this XML feed?

i m 使用下面的脚本来显示来自我网站上的种子的数据。 出于某种原因, 我无法在种子中获取图像以显示 。 我注意到图像地址在其中有一个空间, 我怀疑这是否是问题所在 。 但是, 我更改了种子, 并将空间替换为% 20, 希望它们能够显示。 还是没有运气 。 任何想法吗?

            <?php

            # INSTANTIATE CURL.
            $curl = curl_init();

            # CURL SETTINGS.
            curl_setopt($curl, CURLOPT_URL, "http://www.dpm.uk.com/feeds/rss/product-syndication.ashx?pgid=6&feed=opt1");
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

            # GRAB THE XML FILE.
            $xml = curl_exec($curl);

            curl_close($curl);

            # SET UP XML OBJECT.
            $xmlObj = simplexml_load_string( $xml );

            $tempCounter = 0;

            foreach ( $xmlObj->item as $item )
            {                    
                # DISPLAY ONLY 10 ITEMS.
                if ( $tempCounter < 20 )
                {
                   echo "
                   <div class="feed-item">
                   Title: {$item -> title}
                   Year: {$item -> Year}
                   Colours: {$item -> Colours}
                   Size: {$item -> Size}
                   Available: {$item -> Available}
                   Image: {$item -> Images}
                <br>

                   </div>
                   ";

                }

                $tempCounter += 1;
            }

            ?>
最佳回答
$img = $item->Images->img[0]->attributes();

echo "
  <div class="feed-item">
    Title: {$item->title}
    Year: {$item->Year}
    Colours: {$item->Colours}
    Size: {$item->Size}
    Available: {$item->Available}
    Image: {$img[ src ]}
    <br>
  </div>
";

<强> 更新:

要显示图像 :

echo "Image: <img src="{$img[ src ]}" width="{$img[ width ]}" height="{$img[ height ]}" />";

隐藏全部图像 :

foreach ($item->Images as $img) {
  $img = $img->attributes();
  echo "Image: <img src="{$img[ src ]}" width="{$img[ width ]}" height="{$img[ height ]}" />";
}
问题回答
<?php
error_reporting(E_ALL);

$data = file_get_contents("http://www.dpm.uk.com/feeds/rss/product-syndication.ashx?pgid=6&feed=opt1");
$xml = new SimpleXMLElement($data);
$counter = 0;
foreach ($xml->item as $item) {

    if ($counter < 20){
             echo "<div class="feed-item">
                Title: " . $item->title . ", " . "
                Year:  " . $item->Year . "
        <br></div>";
    }
}
?>

测试过它的工作效果





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签