zoukankan      html  css  js  c++  java
  • php生成XML

    php生成XML
    <?php
    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.'</'.$key.'>'."\n";
         
         }
        }else{
         return '';
        }
        return $xmlstr;
    }
     $news->tablename=$tab['news_news_info'];
     $news->list_news();
     $xml2[]="<?xml version=\"1.0\" encoding=\"utf-8\"?>"."\n";
     $xml2[]="<?xml-stylesheet type=\"text/xsl\" href=\"list_total.xsl\"?>"."\n";
     $xml2[]="<root>";
     foreach($newsinfo as $a=>$b){
      $xml2[]="<item>";
     
      $xml2[]=$news->arraytoxml($b);
     
      $xml2[]="</item>";
     
     }
     
     $xml2[]="</root>";
     $f=fopen("/listnewsxml/list_total.xml","w");
     fwrite($f,join("",$xml2));
     fclose($f);
     unset($newsinfo);
    ?>


    该文章转载自网络大本营:http://www.xrss.cn/Dev/PHP/2007121018093.Html

  • 相关阅读:
    [npm]npm audit fix
    [javascript]中央定时器控制
    [javascript]并发模型与事件循环(Concurrency model and Event loop)
    [翻译][JavaScript] JavaScript 是不是一定是单线程的?
    [DOM][穿梭框][js]运用document.adoptNode方法,写出基础的穿梭框效果
    [document][DOM]document.importNode 与 document.adoptNode
    [DOM][document][进阶]DocumentFragment, document.createDocumentFragment()
    [Object][进阶]Object.defineProperty(),Object.defineProperties(),Object.getOwnPropertyDescriptor()
    [js][字符串]给字符串去空格(全角和半角)
    [vue]mixins在项目中的应用
  • 原文地址:https://www.cnblogs.com/xinyult/p/1209318.html
Copyright © 2011-2022 走看看