2 aind 0 Aind_0 于 2016.03.31 20:47 提问

微信多图文foreach验证失败,求找茬!头要炸了!

请问这段代码哪里有错?

 $newsArr = array(
         array("Title"=>"this is first item",
            "Description"=>"this is first item description",
            "PicUrl"=>"http://img4.imgtn.bdimg.com/it/u=2943793272,3641314298&fm=21&gp=0.jpg",
            "Url"=>"http://www.baidu.com"
         ),
         array("Title"=>"this is second item",
             "Description"=>"this is second item description",
             "PicUrl"=>"http://img2.imgtn.bdimg.com/it/u=945726929,542696667&fm=21&gp=0.jpg",
             "Url"=>"http://www.baidu.com"
         ),
         array("Title"=>"this is thired",
            "Description"=>"this is thired",
            "PicUrl"=>"http://img1.imgtn.bdimg.com/it/u=2783016379,35786742&fm=21&gp=0.jpg",
            "Url"=>"http://www.baidu.com"
         )
);

foreach ($newsArr as $key => $value) {
   $itemstr .= "
         <item>
         <Title><![CDATA[".$value['Title']."]]></Title>
         <Description><![CDATA[".$value['Description']."]]></Description>
         <PicUrl><![CDATA[".$value['PicUrl']."]]></PicUrl>
         <Url><![CDATA[".$value['Url']."]]></Url>
         <item>";
}

   $result = "<xml>
         <ToUserName><![CDATA[%s]]></ToUserName>
         <FromUserName><![CDATA[%s]]></FromUserName>
         <CreateTime>%s</CreateTime>
         <MsgType><![CDATA[news]]></MsgType>
         <ArticleCount>".count($newsArr)."</ArticleCount>
         <Articles>".$itemstr."</Articles>
         </xml>";
   $newsInfo = sprintf($result, $fromUser , $toUser , time());
   echo $newsInfo;

1个回答

runing22
runing22   2016.04.01 15:31
已采纳

item 标签错了

 foreach ($newsArr as $key => $value) {
   $itemstr .= "
         <item>
         <Title><![CDATA[".$value['Title']."]]></Title>
         <Description><![CDATA[".$value['Description']."]]></Description>
         <PicUrl><![CDATA[".$value['PicUrl']."]]></PicUrl>
         <Url><![CDATA[".$value['Url']."]]></Url>
         </item>";
}

Aind_0
Aind_0 回复runing22: 谢谢谢谢谢谢前辈,为了这个差点秃顶!
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!