PHP 和 XML: 使用expat函数(二)
来源:互联网 发布:java 图片合成工具 编辑:程序博客网 时间:2024/05/21 19:40
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
让我们看一下实际处理这个文档的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; /<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
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; /<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- PHP 和 XML: 使用expat函数(二)
- PHP 和 XML: 使用expat函数(一)
- PHP 使用 XML Expat 解释xml文件
- PHP基础之使用Expat解析xml
- PHP XML Expat 解析器
- Expat 解析器 xml php
- PHP XML Expat 解析器
- PHP XML Expat 解析器
- php expat方式解析xml
- 使用expat开发xml分析器
- 使用expat开发xml分析器
- 用PHP工具包expat解析XML
- 用PHP工具包expat解析XML
- 用PHP工具包expat解析XML
- xml expat
- 使用Expat XML解析器的例子
- 关于开源的XML Parser expat的介绍和使用心得
- 开源的XML Parser expat的介绍和使用心得
- GIS开发随笔--GIS技术的一点理解和MapNet控件试验
- 在IIS上安装PHP4.0正式版
- 利用隐藏帧打印url的方法比较
- PHP 和 XML: 使用expat函数(一)
- 封装stream,在读写stream时提供事件通知
- PHP 和 XML: 使用expat函数(二)
- 实例开发:ASP.NET创建网络相册
- PHP中的正规表达式(二)
- “黑盒测试管理”以外的编程经验片断
- 我的程序人生:从老板到程序员 一个失败的“老板
- PHP学习之PHP运算符
- Asp.Net2.0技巧(续)
- php的控制语句
- 动态代理DynamicProxy介绍