仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2333|回复: 18
打印 上一主题 下一主题

[学习教程] PHP教程之PHP中的类-操作XML(3)

[复制链接]
蒙在股里 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-16 00:25:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
不过还好,PHP语言给出的语法错误很详细,只要稍微熟悉一点之后,看错误提示就能很容易找出错误所在的。PHP还有一个特别好用的调试功能,在PHP语句中,你可以随时用echo来输出结果。   

/* Here are the XML functions needed by expat */


   /* when expat hits an opening tag, it fires up this function */

   function startElement($parser, $name, $attrs) {

       array_push($this->current_tag, $name); // add tag to the cur. tag array

       $curtag = implode("_",$this->current_tag); // piece together tag

       /* this tracks what array index we are on for this tag */

       if(isset($this->tagtracker["$curtag"])) {
           $this->tagtracker["$curtag"]++;
       } else {
           $this->tagtracker["$curtag"]=0;
       }


       /* if there are attributes for this tag, we set them here. */

       if(count($attrs)>0) {
           $j = $this->tagtracker["$curtag"];
           if(!$j) $j = 0;

           if(!is_object($GLOBALS[$this->identifier]["$curtag"][$j])) {
               $GLOBALS[$this->identifier]["$curtag"][$j] = new xml_container;
           }

           $GLOBALS[$this->identifier]["$curtag"][$j]->store("attributes",$attrs);
               }

   } // end function startElement



   /* when expat hits a closing tag, it fires up this function */

   function endElement($parser, $name) {

       $curtag = implode("_",$this->current_tag);     // piece together tag
                               // before we pop it off,
                               // so we can get the correct
                               // cdata

       if(!$this->tagdata["$curtag"]) {
           $popped = array_pop($this->current_tag); // or else we screw up where we are
           return;     // if we have no data for the tag
       } else {
           $TD = $this->tagdata["$curtag"];
           unset($this->tagdata["$curtag"]);
       }

       $popped = array_pop($this->current_tag);
                               // we want the tag name for
                               // the tag above this, it  
                               // allows us to group the
                               // tags together in a more
                               // intuitive way.

       if(sizeof($this->current_tag) == 0) return;     // if we aren't in a tag

       $curtag = implode("_",$this->current_tag);     // piece together tag
                               // this time for the arrays

       $j = $this->tagtracker["$curtag"];
       if(!$j) $j = 0;

       if(!is_object($GLOBALS[$this->identifier]["$curtag"][$j])) {
           $GLOBALS[$this->identifier]["$curtag"][$j] = new xml_container;
       }

       $GLOBALS[$this->identifier]["$curtag"][$j]->store($name,$TD); #$this->tagdata["$curtag"]);
       unset($TD);
       return TRUE;
   }



   /* when expat finds some internal tag character data,
      it fires up this function */

   function characterData($parser, $cdata) {
       $curtag = implode("_",$this->current_tag); // piece together tag         
       $this->tagdata["$curtag"] .= $cdata;
   }


   /* this is the constructor: automatically called when the class is initialized */

   function xml($data,$identifier='xml') {   

       $this->identifier = $identifier;

       // create parser object
       $this->xml_parser = xml_parser_create();

       // set up some options and handlers
       xml_set_object($this->xml_parser,$this);
       xml_parser_set_option($this->xml_parser,XML_OPTION_CASE_FOLDING,0);
       xml_set_element_handler($this->xml_parser, "startElement", "endElement");
       xml_set_character_data_handler($this->xml_parser, "characterData");

       if (!xml_parse($this->xml_parser, $data, TRUE)) {
           sprintf("XML error: %s at line %d",
           xml_error_string(xml_get_error_code($this->xml_parser)),
           xml_get_current_line_number($this->xml_parser));
       }

       // we are done with the parser, so let's free it
       xml_parser_free($this->xml_parser);

   }  // end constructor: function xml()


} // thus, we end our class xml

?>

怎么培养啊 别光说不练啊,好 ,比如新人入门自己步是配置环境,虽然现在都有很多的集成环境,但是真实的体验下配置环境还是会有很多帮助,不论是你以后工作还是在真实的linux下开发。
第二个灵魂 该用户已被删除
沙发
发表于 2015-2-16 01:51:53 | 只看该作者
建议加几个专业的phper的群,当然啦需要说话的人多,一处一点问题能有人回答你的,当然啦要让人回答你的问题,平时就得躲在里面聊天,大家混熟啦,愿意回答你问题的人自然就多啦。
小女巫 该用户已被删除
板凳
发表于 2015-2-16 23:21:23 | 只看该作者
对于懒惰的朋友,我推荐php的集成环境xampp或者是wamp。这两个软件安装方便,使用简单。但是我还是强烈建议自己动手搭建开发环境。
乐观 该用户已被删除
地板
发表于 2015-3-7 22:02:27 | 只看该作者
基础有没有对学习php没有太大区别,关键是兴趣。
变相怪杰 该用户已被删除
5#
发表于 2015-3-11 09:06:02 | 只看该作者
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,
admin 该用户已被删除
6#
发表于 2015-3-18 01:58:55 | 只看该作者
基础有没有对学习php没有太大区别,关键是兴趣。
小妖女 该用户已被删除
7#
发表于 2015-3-19 09:45:45 | 只看该作者
这些中手常用的知识,当你把我说的这些关键字都可以熟练运用的时候,你可以选择自己
小魔女 该用户已被删除
8#
发表于 2015-3-25 12:29:15 | 只看该作者
个人呢觉得,配wamp 最容易漏的一步就是忘了把$PHP$目录下的libmysql.dll拷贝到windows系统目录的system32目录下,还有重启apache。
海妖 该用户已被删除
9#
发表于 2015-4-4 09:27:00 | 只看该作者
开发工具也会慢慢的更专业,每个公司的可能不一样,但是zend studio是个大伙都会用的。
深爱那片海 该用户已被删除
10#
发表于 2015-4-6 06:41:19 | 只看该作者
为了以后维护的方便最好是代码上都加上注释,“予人方便,自己方便”。此外开发文档什么的最好都弄齐全。我觉得这是程序员必备的素质。虽然会消耗点很多的时间。但是确实是非常有必要的。
柔情似水 该用户已被删除
11#
发表于 2015-4-13 00:24:29 | 只看该作者
php是动态网站开发的优秀语言,在学习的时候万万不能冒进。在系统的学习前,我认为不应该只是追求实现某种效果,因为即使你复制他人的代码调试成功,实现了你所期望的效果,你也不了解其中的原理。
莫相离 该用户已被删除
12#
发表于 2015-4-16 07:12:57 | 只看该作者
其实没啥难的,多练习,练习写程序,真正的实践比看100遍都有用。不过要熟悉引擎
活着的死人 该用户已被删除
13#
发表于 2015-4-17 21:10:18 | 只看该作者
写js我最烦的就是 ie 和 firefox下同样的代码 结果显示的结果千差万别,还是就是最好不要用遨游去调试,因为有时候遨游是禁用js的,有可能代码是争取结果被遨游折腾的认为是代码写错。
再见西城 该用户已被删除
14#
发表于 2015-4-22 20:48:39 | 只看该作者
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
山那边是海 该用户已被删除
15#
发表于 2015-4-26 08:11:55 | 只看该作者
写的比较杂,因为我也是个新手,不当至于大家多多指正。
透明 该用户已被删除
16#
发表于 2015-5-4 12:46:18 | 只看该作者
我还是推荐用firefox ,配上firebug 插件调试js能省下不受时间。谷歌的浏览器最好也不少用,因为谷歌的大侠们实在是太天才啦,把一些原来的js代码加了一些特效。
灵魂腐蚀 该用户已被删除
17#
发表于 2015-5-7 14:29:17 | 只看该作者
爱上php,他也会爱上你。
金色的骷髅 该用户已被删除
18#
发表于 2015-6-11 07:13:49 | 只看该作者
做为1门年轻的语言,php一直很努力。
老尸 该用户已被删除
19#
发表于 2015-6-22 10:51:19 | 只看该作者
再就是混迹于论坛啦,咱们的phpchina的论坛就很强大,提出的问题一般都是有达人去解答的,以前的帖子也要多看看也能学到不少前辈们的经验。别的不错的论坛例如php100,javaeye也是很不错的。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-21 01:44

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表