【问题标题】:Displaying images in rss description tag with php使用 php 在 rss 描述标签中显示图像
【发布时间】:2012-09-02 22:30:46
【问题描述】:

我试图在我的 rss 中的描述标签旁边或之前显示一个图像,我已经在我的本地主机上尝试过它的工作方式如下:

<description><![CDATA[<img src="<?php echo $img; ?>">test test test test testtest test test test]]></description>

但在我的网站上却有些不同,如下所示:

echo '
       <item>
          <title>'.$article[title].'</title>
          <description><![CDATA[<img src="$img_path">
          '.$shortdesc.'  
          ]]></description>
      </item>';

它不是这样工作的,这首颂歌有什么问题?它返回空白iamge,这是来自浏览器的页面源:

<description><![CDATA[<img src="$img_path">test test test</description>

【问题讨论】:

    标签: php html xml image rss


    【解决方案1】:

    单引号内的 PHP 代码不会被解析。

    echo '
           <item>
              <title>'.$article['title']."</title>
              <description><![CDATA[<img src='{$img_path}'>
              ".$shortdesc.'  
              ]]></description>
          </item>';
    

    echo '
           <item>
              <title>'.$article['title'].'</title>
              <description><![CDATA[<img src="'.$img_path.'">
              '.$shortdesc.'  
              ]]></description>
          </item>';
    

    【讨论】:

    • it;s 返回:“语法错误,意外的 T_VARIABLE,期待 ',' 或 ';'在"
    • 他们都返回这个:
    • 那么 $img_path 必须在你的脚本中丢失或为空。
    • 天哪,这是怎么传给我的,你是对的,它是空白的,非常感谢,现在它工作得很好
    猜你喜欢
    • 1970-01-01
    • 2020-08-25
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多