php產生XML

來源:互聯網
上載者:User
php產生XML
function list_news($id){
global $db;
global $newsinfo;
$sql="SELECT * FROM {$this->tablename}";
if($id){

$sql.=" WHERE news_news_id=".$id;

}
$re=$db->query($sql);
while($r=$db->fetch_array($re)){

$newsinfo[]=array(
'news_news_id' =>$r['news_news_id'],

'news_news_name' =>$r['news_news_name'],
'news_category_id' =>$r['news_category_id'],
'news_tag_name' =>$r['news_tag_name'],
'news_content_info' =>$r['news_content_info'],
'news_news_author' =>$r['news_news_author'],
'news_is_adit' =>$r['news_is_adit'],
'news_is_cancle' =>$r['news_is_cancle'],
'news_pub_time' =>$r['news_pub_time'],
'news_is_recommand' =>$r['news_is_recommand'],
'news_is_hot' =>$r['news_is_hot'],
'news_is_settop' =>$r['news_is_settop'],
'news_keyword_info' =>$r['news_keyword_info'],
'news_title_color' =>$r['news_title_color'],
'news_introduction_info' =>$r['news_introduction_info'],
'news_hit_count' =>$r['news_hit_count'],
'news_xml_path' =>$r['news_xml_path'],
'news_source_info' =>$r['news_source_info']


);
}
}

function arraytoxml($iarr){
if (is_array($iarr)) {
foreach ($iarr as $key =>$v) {
$xmlstr .='<'.$key.'>'.$v.''."\n";

}
}else{
return '';
}
return $xmlstr;
}
$news->tablename=$tab['news_news_info'];
$news->list_news();
$xml2[]=""."\n";
$xml2[]=""."\n";
$xml2[]="";
foreach($newsinfo as $a=>$b){
$xml2[]="";

$xml2[]=$news->arraytoxml($b);

$xml2[]="";

}

$xml2[]="";
$f=fopen("/listnewsxml/list_total.xml","w");
fwrite($f,join("",$xml2));
fclose($f);
unset($newsinfo);
?>


該文章轉載自網路大本營:http://www.xrss.cn/Dev/PHP/2007121018093.Html

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.