基於xml+xslt+css+php快速構建可擴充網站_PHP教程

來源:互聯網
上載者:User
1.讓資料與顯示分離 test.xml 資料: test titletest contentbannersidebarmain bodyend of the page test.xslt 模板: test<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2.網頁自動產生 php 程式讀入config檔案根據檔案中指定的目標檔案名 和 資料檔案名 以及 模板檔案名稱產生目標頁面 config 檔案: test.htmltest.xmltest.xslt php 代碼: load(”$xsl”); $xmlDoc = new DOMDocument();$xmlDoc->load(”$xml”); $proc = new XSLTProcessor();$proc->importStylesheet($xslDoc);$html = $proc->transformToXML($xmlDoc); if (!($filehandler = fopen($name, “w+”))){die(”could not open $name output”);} fwrite($filehandler, $html); fclose($filehandler);} $parser = xml_parser_create(); xml_set_element_handler($parser, “startElement”, “endElement”);xml_set_character_data_handler($parser, “characterData”); if (!($filehandler = fopen($xml_file, “r”))){die(”could not open XML input”);} while ($data = fread($filehandler, 4096)){if (!xml_parse($parser, $data, feof($filehandler))){die(sprintf(”XML error: %s at line %d”,xml_error_string(xml_get_error_code($parser)),xml_get_current_line_number($parser)));}} fclose($filehandler);xml_parser_free($parser); foreach ($arr as $sub_arr){$i = 0;foreach ($sub_arr as $obj){if ($i == 0){$name = $obj;} if ($i == 1){$xml = $obj;} if ($i == 2){$xsl = $obj;} $i++;}buildHtml($name, $xml, $xsl); } ?> 3.重新規劃整個頁面 這樣的分拆式設計可以使頁面更靈活,隨意修改任何部分都不會影響到其餘的塊,並且可以不斷變換其中的某個塊的資料 比如:body.xml 來產生更多新的頁面, 特別適合新聞系統或論壇使用 top.xml:

http://www.bkjia.com/PHPjc/486275.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486275.htmlTechArticle1.讓資料與顯示分離 test.xml 資料: xml titletest title/title contenttest content/content topbanner/top leftsidebar/left bodymain body/body endend of the page/end /xml test...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.