仓酷云

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

[学习教程] PHP网页设计PHP中的类-操作XML(1)

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

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

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

x
应该大致熟悉了一些学习过程,也许我的过程和你的有些出路,但是不管怎么样是殊途同归,我写这么多,也只是给大家一个借鉴的机会,至于好与不好,默默不敢打包票^0^   

http://www.hansanderson.com/ me

<?php

/*
   (c) 2000 Hans Anderson Corporation.  All Rights Reserved.
   You are free to use and modify this class under the same
   guidelines found in the PHP License.

   -----------

   bugs/me:
   http://www.hansanderson.com/php/
   me@hansanderson.com

   -----------

   Version 1.0

       - 1.0 is the first actual release of the class.  It's  
         finally what I was hoping it would be, though there
         are likely to still be some bugs in it.  This is
         a much changed version, and if you have downloaded
         a previous version, this WON'T work with your existing
         scripts!  You'll need to make some SIMPLE changes.

       - .92 fixed bug that didn't include tag attributes

         (to use attributes, add _attributes[array_index]
          to the end of the tag in question:
           $xml_html_head_body_img would become
           $xml_html_head_body_img_attributes[0],  
          for example)

          -- Thanks to Nick Winfield <nick@wirestation.co.uk>
             for reporting this bug.

       - .91 No Longer requires PHP4!

       - .91 now all elements are array.  Using objects has
         been discontinued.

   -----------

   What class.xml.php is:

   A very, very easy to use XML parser class. It uses PHP's XML functions
   for you, returning one array that has all the tag information.  The only  
   hard part is figuring out the syntax of the tags!

   -----------

   Sample use:

   require('class.xml.php');
   $file = "data.xml";
   $data = implode("",file($file)) or die("could not open XML input file");
   $obj = new xml($data,"xml");


   print $xml["hans"][0]->num_results[0];
   for($i=0;$i<sizeof($xml["hans"]);$i++) {
    print $xml["hans"][$i]->tag[0] . " ";
   }

   To print url attributes (if they exist):

   print $xml["hans"][0]->attributes[0]["size"]; # where "size" was an attr name

   (that's it! slick, huh?)
   -----------

   Two ways to call xml class:  

       $xml = new xml($data);
       - or -
       $xml = new xml($data,"jellyfish");

   The second argument (jellyfish) is optional.  Default is 'xml'.
   All the second argument does is give you a chance to name the array
   that is returned something besides "xml" (in case you are already using
   that name).  Normal PHP variable name rules apply.

   ----------

   Explanation of xml class:

   This class takes valid XML data as an argument and  
   returns all the information in a complex but loopable array.

   Here's how it works:

       Data:

           <html>
            <head>
             <title>Hans Anderson's XML Class</title>
            </head>
            <body>
            </body>
           </html>

       Run the data through my class, then access the title like this:
       $xml["html_head"][0]->title[0];

       Or, loop through them:
       for($i=0;$i<sizeof($xml["html_head"]);$i++) {
           print $xml["html_head"][$i]->title[0] . " ";
       }

       Yes, the variable names *are* long and messy, but it's
       the best way to create the tree, IMO.


Here is a complex explanation I sent to one class.xml.php user:

---------

> Now I've run into another problem:
>
> <STORY TIMESTAMP="2000-12-15T20:08:00,0">
> <SECTION>Markets</SECTION>
> <BYLINE>By <BYLINE_AUTHOR ID="378">Aaron L. Task</BYLINE_AUTHOR><BR/>Senior
> Writer</BYLINE>
> </STORY>
>
> How do I get BYLINE_AUTHOR?

print $xml["STORY_BYLINE"][0]->BYLINE_AUTHOR[0];

> And just a little question: Is there an easy way to get TIMESTAMP?

print $xml["STORY"][0]->attributes[0]["TIMESTAMP"];

This is confusing, I know, but it's the only way I could really do
this.  Here's the rundown:

The $xml part is an array -- an array of arrays.  The first array is the
刚开始因为习惯于ASP格式的写法,总是在这些方面出现问题,自己还总是找不到问题所在,这就提醒了自己,在写代码的时候一定要认真,不能粗心地老是少个“;”或者字母大小写不分,要不然很可能找半天都找不到错误。
再现理想 该用户已被删除
21#
发表于 2015-5-1 07:09:01 | 只看该作者
实践是检验自己会不会的真理。
莫相离 该用户已被删除
20#
发表于 2015-4-22 20:48:39 | 只看该作者
小鸟是第一次发帖(我习惯潜水的(*^__^*) 嘻嘻……),有错误之处还请大家批评指正,另外,前些日子听人说有高手能用php写驱动程序,真是学无止境,人外有人,天外有天。
小女巫 该用户已被删除
19#
发表于 2015-4-22 10:36:27 | 只看该作者
没接触过框架的人,也不用害怕,其实框架就是一种命名规范及插件,学会一个框架其余的框架都很好上手的。
再见西城 该用户已被删除
18#
发表于 2015-4-21 08:13:44 | 只看该作者
开发工具也会慢慢的更专业,每个公司的可能不一样,但是zend studio是个大伙都会用的。
深爱那片海 该用户已被删除
17#
发表于 2015-4-18 16:21:59 | 只看该作者
这些中手常用的知识,当你把我说的这些关键字都可以熟练运用的时候,你可以选择自己
愤怒的大鸟 该用户已被删除
16#
发表于 2015-4-17 21:10:18 | 只看该作者
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81
只想知道 该用户已被删除
15#
发表于 2015-4-14 09:10:31 | 只看该作者
我还是强烈建议自己搭建php环境。因为在搭建的过程中你会遇到一些问题,通过搜索或是看php手册解决问题后,你会更加深刻的理解它们的工作原理,了解到php配置文件中的一些选项设置。
小妖女 该用户已被删除
14#
发表于 2015-4-11 03:31:08 | 只看该作者
首先我是坚决反对新手上来就用框架的,因为对底层的东西一点都不了解,造成知识上的真空,会对以后的发展不利。我的观点上手了解下框架就好,代码还是手写。当然啦如果是位别的编程语言的高手的话,这个就另当别论啦。
若相依 该用户已被删除
13#
发表于 2015-3-25 02:35:18 | 只看该作者
写的比较杂,因为我也是个新手,不当至于大家多多指正。
透明 该用户已被删除
12#
发表于 2015-3-24 22:03:07 | 只看该作者
我还是强烈建议自己搭建php环境。因为在搭建的过程中你会遇到一些问题,通过搜索或是看php手册解决问题后,你会更加深刻的理解它们的工作原理,了解到php配置文件中的一些选项设置。
老尸 该用户已被删除
11#
发表于 2015-3-24 11:45:39 | 只看该作者
遇到出错的时候,我经常把错误信息直接复制到 google的搜索栏,一般情况都是能搜到结果的,不过有时候会搜出来一大片英文的出来,这时候就得过滤一下,吧中文的弄出来,挨着式方法。
兰色精灵 该用户已被删除
10#
发表于 2015-3-22 23:55:54 | 只看该作者
我还是推荐用firefox ,配上firebug 插件调试js能省下不受时间。谷歌的浏览器最好也不少用,因为谷歌的大侠们实在是太天才啦,把一些原来的js代码加了一些特效。
变相怪杰 该用户已被删除
9#
发表于 2015-3-19 18:38:07 | 只看该作者
我还是强烈建议自己搭建php环境。因为在搭建的过程中你会遇到一些问题,通过搜索或是看php手册解决问题后,你会更加深刻的理解它们的工作原理,了解到php配置文件中的一些选项设置。
精灵巫婆 该用户已被删除
8#
发表于 2015-3-15 21:54:33 | 只看该作者
我还是推荐用firefox ,配上firebug 插件调试js能省下不受时间。谷歌的浏览器最好也不少用,因为谷歌的大侠们实在是太天才啦,把一些原来的js代码加了一些特效。
不帅 该用户已被删除
7#
发表于 2015-3-15 13:08:43 | 只看该作者
首先声明:我是一个菜鸟,是一个初学者。学习了一段php后总是感觉自己没有提高,无奈。经过反思我认为我学习过程中存在很多问题,我改变了学习方法后自我感觉有了明显的进步。
admin 该用户已被删除
6#
发表于 2015-3-14 12:30:32 | 只看该作者
建数据库表的时候,int型要输入长度的,其实是个摆设的输入几位都没影响的,只要大于4就行,囧。
第二个灵魂 该用户已被删除
5#
发表于 2015-3-13 22:07:26 | 只看该作者
曾经犯过一个很低级的错误,我在文件命名的时候用了一个横线\\\\\\\'-\\\\\\\' 号,结果找了好几个小时的错误,事实是命名的时候 是不能用横线 \\\\\\\'-\\\\\\\' 的,应该用的是下划线  \\\\\\\'_\\\\\\\' ;
爱飞 该用户已被删除
地板
发表于 2015-3-6 22:46:58 | 只看该作者
开发工具也会慢慢的更专业,每个公司的可能不一样,但是zend studio是个大伙都会用的。
简单生活 该用户已被删除
板凳
发表于 2015-3-4 22:09:53 | 只看该作者
对于初学者来说不推荐去拿钱买的。当然如果一个网站你经常去用,而且里面的资料也比较有用,最好还是买个会员比较好,毕竟那些也是别人的工作成果。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-9-20 20:45

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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