Php 如何在XML文件中插入图像标记?
我使用以下php代码创建XML文件:Php 如何在XML文件中插入图像标记?,php,xml,Php,Xml,我使用以下php代码创建XML文件: echo '<?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> <channel> <title>mytitle</title> <description>my description</description> <link>www.mysite.com</link>'
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>mytitle</title>
<description>my description</description>
<link>www.mysite.com</link>';
$sql = "SELECT title, description, url, picture, formatted_date
FROM somewhere" ;
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
//timestamp date to xml format
$pubdate = date('D, d M Y H:i:s O', strtotime($result_array[formatted_date]));
echo '
<item>
<title>'.$result_array[title].'</title>
<description>'.$result_array[description].'</description>
<link>'.$result_array[indit_url].'</link>
<pubDate>'.$pubdate.' GMT</pubDate>
<enclosure url="'.$result_array[picture].'" length="1121990" type="image"/>
<image>
<url>'.$result_array[picture].'</url>
<title>image title</title>
<link>'.$result_array[picture].'</link>
<width>111</width>
<height>33</height>
<description>An amazing picture</description>
</image> </item>';
echo'
我的头衔
我的描述
www.mysite.com';
$sql=“选择标题、说明、url、图片、格式化日期
“从某处来”;
$result=mysql\u查询($sql);
如果(!$result){
die('无效查询:'.mysql_error());
}
如果(mysql_num_rows($result)>0)
{
而($result\u array=mysql\u fetch\u assoc($result))
{
//xml格式的时间戳日期
$pubdate=date('D,dmy H:i:so',strottime($result\u array[formatted\u date]);
回声'
“.$result_数组[标题]。”
“.$result_数组[说明]。”
“.$result\u数组[indit\u url]”
“.$pubdate.”格林威治标准时间
“.$result_数组[图片]。”
图像标题
“.$result_数组[图片]。”
111
33
一张令人惊奇的照片
';
创建的文件已使用正确验证,但当我尝试使用某些xml解析器时,例如:perser无法捕获图像。我是否使用正确的标记将图像插入xml文件?是否有其他标记或方法插入图像?请尝试转义图像标记中的特殊字符 在
$result\u数组[图片]
另外,您能否在此处显示rss提要的示例,以便更准确地回答问题。我建议将数据放在XML转义结构中—例如:
<image>
<url><![CDATA[ imagedatagoeshere ]]></content></url>
</image>
但是,我不熟悉simplepie,所以我不知道它是否正确理解CDATA。xml不关心您是否插入图像或文本或其他内容。它只是一种标记语言。它没有“图像”。Mark B说了什么。也许您想看看?