仓酷云

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

[学习教程] PHP网页编程之PHP中的类-操作XML(2)

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

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

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

x
理解网站这一概念之后不难看出,任何网站都是由网页组成的,也就是说想完成网站,必须先学会做网页,因此必须要掌握了HTML,才能为今后制作网站打下基础。   

name of the tag -- in the first case above, this is the tag STORY, and
below that BYLINE.  You want BYLINE_AUTHOR.  You want the first BA.  The
first one is index [0] in the second part of the two-dimensional array.

Even if there is only *one* byline author, it's still an array, and you
still have to use the [0].  Now, the two-dimensional array is storing
dynamic structures -- objects in this case.  So, we need to dereference
the object, hence the ->.  The BYLINE_AUTHOR is the tag you want, and it
is an array in that object.  The reason for the array is that if there are
more than one BYLINE_AUTHOR for the tags STORY, BYLINE, we would have a
[0] and [1] in the array.  In your case there is just the one.

*** This is very confusing, I know, but once you understand it, the power
of this method will be more apparent.  You have access to *every* bit of
information in the XML file, without having to do anything but understand
how to refer to the variables. ***

EVERY variable will look like this:
       print $xml["STORY_BYLINE"][0]->BYLINE_AUTHOR[0];

The trick is understanding how to get the variable to give you the
information.  This is an array of arrays of objects holding arrays!

Any tag that has attributes will have them stored in a special object
array named "attributes" and will be called this way:

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

If you aren't sure if there are attributes, you could do isset() or
is_array() for that above example.  If isset(), you could for loop and
while(list($k,$v) = each($xml...)) over it to get the values.


         array of
                 objects
                    |
                    |
$xml["STORY_BYLINE"][0]->BYLINE_AUTHOR[0];
          ^                    ^
       array of                ^
        arrays                 ^
                               ^
                            array in
                             object

In general, to get the value of this:

<STATE>
       <STATENAME></STATENAME>
       <COUNTY>
               <COUNTYNAME></COUNTYNAME>
               <CITY></CITY>
               <CITY></CITY>
       </COUNTY>
       <COUNTY>
               <COUNTYNAME></COUNTYNAME>
               <CITY></CITY>
               <CITY></CITY>
       </COUNTY>
</STATE>

You would look for what you want, say "CITY", then go UP one level, to
COUNTY (COUNTYNAME is on the same 'level'), for your first array:

$xml["STATE_COUNTY"] -- ALL tags pushed together are separated with
"_".  Otherwise tags are as they were -- spaces, dashes, CaSe, etc.

Now, you want the first COUNTY, though there are two, so we are do this:

$xml["STATE_COUNTY"][0] -- to get the second, we'd use [1] instead of
[0].  You could also do a for() loop through it, using sizeof() to figure
out how big it is.

So, we have the STATE,COUNTY we want -- the first one.  It's an
object, and we know we want the CITY.  So, we dereference the object.  The
name of the array we want is, of course, CITY:

$xml["STATE_COUNTY"][0]->CITY[0] (the first one, the second one would be
[1]).

And that's it.  Basically, find what you want, and go up a level.

You could do some complex for loops to go through them all, too:

for($i=0;$i<sizeof($xml["STATE_COUNTY"]);$i++) {

       for($j=0;$j<sizeof($xml["STATE_COUNTY"][0]->CITY);$j++) {

               print $xml["STATE_COUNTY"][$i]->CITY[$j];

       }

}

-----------

Whew.  I hope that helps, not hurts.

*/

/* used to store the parsed information */
class xml_container {

   function store($k,$v) {
       $this->{$k}[] = $v;
   }

}


/* parses the information */
class xml {  

   // initialize some variables
   var $current_tag=array();
   var $xml_parser;
   var $Version = 1.0;
   var $tagtracker = array();
在学习中,我也一直这样要求着自己。
再见西城 该用户已被删除
沙发
发表于 2015-2-16 01:53:28 | 只看该作者
我要在声明一下:我是个菜鸟!!我对php这门优秀的语言也是知之甚少。但是我要在这里说一下php在网站开发中最常用的几个功能:
金色的骷髅 该用户已被删除
板凳
发表于 2015-3-4 22:06:42 | 只看该作者
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81
莫相离 该用户已被删除
地板
发表于 2015-3-7 22:02:27 | 只看该作者
其实没啥难的,多练习,练习写程序,真正的实践比看100遍都有用。不过要熟悉引擎
变相怪杰 该用户已被删除
5#
发表于 2015-3-11 09:06:02 | 只看该作者
我还是强烈建议自己搭建php环境。因为在搭建的过程中你会遇到一些问题,通过搜索或是看php手册解决问题后,你会更加深刻的理解它们的工作原理,了解到php配置文件中的一些选项设置。
深爱那片海 该用户已被删除
6#
发表于 2015-3-14 12:30:32 | 只看该作者
微软最近出的新字体“微软雅黑”,虽然是挺漂亮的,不过firefox  支持的不是很好,所以能少用还是少用的好。
小妖女 该用户已被删除
7#
发表于 2015-3-19 18:38:07 | 只看该作者
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
灵魂腐蚀 该用户已被删除
8#
发表于 2015-3-24 11:45:39 | 只看该作者
学好程序语言,多些才是王道,写两个小时代码的作用绝对超过看一天书,这个我是深有体会(顺便还能练打字速度)。
分手快乐 该用户已被删除
9#
发表于 2015-3-27 22:10:55 | 只看该作者
这些中手常用的知识,当你把我说的这些关键字都可以熟练运用的时候,你可以选择自己
admin 该用户已被删除
10#
发表于 2015-4-6 06:41:19 | 只看该作者
说php的话,首先得提一下数组,开始的时候我是最烦数组的,总是被弄的晕头转向,不过后来呢,我觉得数组里php里最强大的存储方法,所以建议新手们要学好数组。
飘飘悠悠 该用户已被删除
11#
发表于 2015-4-8 15:12:07 | 只看该作者
刚开始安装php的时候,我图了个省事,把php的扩展全都打开啦(就是把php.ini 那一片 extension 前面的冒号全去掉啦),这样自然有好处,以后不用再需要什么功能再来打开。
精灵巫婆 该用户已被删除
12#
发表于 2015-4-11 03:31:08 | 只看该作者
本人接触php时间不长,算是phper中的小菜鸟一只吧。由于刚开始学的时候没有名师指,碰过不少疙瘩,呗很多小问题卡过很久,白白浪费不少宝贵的时间,在次分享一些子的学习的心得。
若相依 该用户已被删除
13#
发表于 2015-4-16 07:12:57 | 只看该作者
你很难利用原理去编写自己的代码。对于php来说,系统的学习我认为还是很重要的,当你有一定理解后,你可你针对某种效果研究,我想那时你不会只是复制代码的水平了。
若天明 该用户已被删除
14#
发表于 2015-4-17 21:10:18 | 只看该作者
说php的话,首先得提一下数组,开始的时候我是最烦数组的,总是被弄的晕头转向,不过后来呢,我觉得数组里php里最强大的存储方法,所以建议新手们要学好数组。
兰色精灵 该用户已被删除
15#
发表于 2015-4-22 20:48:39 | 只看该作者
个人呢觉得,配wamp 最容易漏的一步就是忘了把$PHP$目录下的libmysql.dll拷贝到windows系统目录的system32目录下,还有重启apache。
飘灵儿 该用户已被删除
16#
发表于 2015-5-1 15:10:27 | 只看该作者
学好程序语言,多些才是王道,写两个小时代码的作用绝对超过看一天书,这个我是深有体会(顺便还能练打字速度)。
活着的死人 该用户已被删除
17#
发表于 2015-6-11 07:13:49 | 只看该作者
实践是检验自己会不会的真理。
小魔女 该用户已被删除
18#
发表于 2015-6-18 07:40:30 | 只看该作者
开发工具也会慢慢的更专业,每个公司的可能不一样,但是zend studio是个大伙都会用的。
透明 该用户已被删除
19#
 楼主| 发表于 2015-6-20 21:53:17 | 只看该作者
遇到出错的时候,我经常把错误信息直接复制到 google的搜索栏,一般情况都是能搜到结果的,不过有时候会搜出来一大片英文的出来,这时候就得过滤一下,吧中文的弄出来,挨着式方法。
柔情似水 该用户已被删除
20#
发表于 2015-7-3 00:21:52 | 只看该作者
遇到出错的时候,我经常把错误信息直接复制到 google的搜索栏,一般情况都是能搜到结果的,不过有时候会搜出来一大片英文的出来,这时候就得过滤一下,吧中文的弄出来,挨着式方法。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-5-3 00:00

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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