php专区

 首页 > php专区 > PHP应用 > php函数大全 > PHP 和 XML: 使用expat函数(二)

PHP 和 XML: 使用expat函数(二)

分享到:
【字体:
导读:
          PHP 和 XML: 使用expat函数(二)  让我们看一下实际处理这个文档的PHP代码。 *NewsBoy : News system for the web written in PHP by Justin Grant (Web: jusgrant cjb net or justin host

  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; //} }*/
分享到:
字符串操作函数
  PHP3.0中的字符串操作功能是比较多的,重要的有以下这些: (1)echo,print,printf,sprintf 用于输出字符串.字符串中如果有变量名则被替换成其值. 后两个函数类似于C的同名函数.   (2)strchr, strlen, strtok, strrchr, strrev, strstr, strtolower, strtoupper, substr, ucfirst 用的字符串操作函数,有些和C中的同名...
很有用的php函数
  很有用的一些函数,你可以作为源码保存,然后以后避免重复编写。 文件读取函式    //文件读取函式    function PHP_Read($file_name) {    $fd=fopen($file_name,r);    while($bufline=fgets($fd, 4096)){    $buf.=$bufline;     }    fclose($fd);    return $buf;     }    ?> 文...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……