PHP and XML: Use the expat function (2)

Source: Internet
Author: User
Tags php class php and php code
PHP and XML: Use the expat function (2)
Let's take a look at the PHP code that actually processes this document.
/* 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 ;//}}*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.