PHP 和 XML: 使用expat函数(二)
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-05-24
PHP 和 XML: 使用expat函数(二) 让我们看一下实际处理这个文档的PHP代码。 /*NewsBoy : News system for the web written in PHP by Justin Grant (Web: jusgrant.cjb.net or justin.host.za.net Mail: justin@glendale.net)25 March V0.0.2 Converted Newsboy to a PHP class, allowing the layout to be easily modified. Also added made the HTML that is genrated a little easier to read.24 March V0.0.1 Just completed the intial version, very rough and basic.*/ class newsboy { var $xml_parser; var $xml_file; var $html; var $open_tag ; var $close_tag ; //Class Constructor function newsboy() { $this->xml_parser = ""; $this->xml_file = ""; $this->html = ""; $this->open_tag = array( //these are the default settings but they are quite easy to modify "NEWSBOY" => "nn", "STORY" => " ", "DATE" => "", "SLUG" => " ", "TEXT" => "", "PIC" => "", "NEWLINE" => "" ); $this->close_tag = array( "NEWSBOY" => " nnn", "STORY" => "", "DATE" => "", "SLUG" => " ", "TEXT" => "n", "PIC" => " " " ); } //Class Destructor (has to be invoked manually as PHP does not support destructors) function destroy() { xml_parser_free($this->xml_parser); } //Class Members function concat($str) { $this->html .= $str; } function startElement($parser, $name, $attrs) { //global $open_tag; if ($format= $this->open_tag[$name]) { $this->html .= $format; } } function endElement($parser, $name) { global $close_tag; if ($format= $this->close_tag[$name]) { $this->html .= $format; } } function characterData($parser, $data) { $this->html .= $data; } /* function PIHandler($parser, $target, $data) { //switch (strtolower($target)){ // case "php": eval($data); // break; / |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: 怎样在UNIX系统下安装MySQL下一篇: 怎样在UNIX系统下安装php3
关于PHP 和 XML: 使用expat函数(二) 的所有评论