Php Xml解析之DOMDocument使用方法浅解
用到的XML文件还以“Php Xml处理之simplexml使用方法浅谈”一文中的XML为例,文件名为:me.xml。代码如下:
PHP XML处理XML代码
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
phplamp
>
<
post
>
<
title
id
=
"1"
>
PHP XML处理介绍一
</
title
>
<
details
>
详细内容一
</
details
>
</
post
>
<
post
>
<
title
id
=
"2"
>
PHP XML处理介绍二
</
title
>
<
details
>
详细内容二
</
details
>
</
post
>
<
post
>
<
title
id
=
"3"
>
PHP XML处理介绍三
</
title
>
<
details
>
详细内容三
</
details
>
</
post
>
</
phplamp
>
然后就需要用PHP的DOMDocument去处理这个文件,将XML文件中的任何元素都解析出来。代码如下,里面有注释。
PHP Xml解析DOMDocument代码
<?php
// 首先要建一个DOMDocument对象
$xml
=
new
DOMDocument();
// 加载Xml文件
$xml
->load(
"me.xml"
);
// 获取所有的post标签
$postDom
=
$xml
->getElementsByTagName(
"post"
);
// 循环遍历post标签
foreach
(
$po
相关文档:
可以简单的有两个for循环表示 九九乘法表,但是并不知道如何进行URL的设置.
<?php
for($a =1;$a<=9;$a++)
{
for($b =1;$b<=$a;$b++)
{$c =$a *$b;
echo "$a*$b=$c ";
}
echo "<p>";
}
?> ......
asp,asp.net,php,jsp下的301转向代码
使用.htaccess文件来进行301重定向。
如果空间不支持.htaccess文件,那么我们还可以通过php/asp代码来进行301重定向。
为了将搜索引擎的记录更新到现在的域名上面,做了几个301重定向的东东,给大家分享一下.
asp 301转向代码
在 index.asp 或 default.asp 的最顶部加入以 ......
无意间看到以前发的帖子.回忆起那些PHP的日日夜夜
http://www.phpfans.net/ask/discuss2/343326196.html
<?
class gzg//钙中钙类
{
var $x;//属性
function gzg()//构造函数,默认不吃钙中钙
&n ......
//创建文件夹的方法
//$path 为文件夹参数,如 (c:/program files/makedir)
function createFolders($path) {
if (!file_exists($path)) {
$this->createFolders(dirname($path));
mkdir($path, 0777);
&n ......