php中dom生成的xml如何输出到页面上 dom xml 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你这是创建的xml,你得些一个程序读取xml1)DOMDocument读取xml<?php $doc = new DOMDocument(); $doc->load('person.xml'); //读取xml文件 $humans = $doc->getElementsByTagName( "humans" ); //取得humans标签的对象数组 foreach( $humans as $human ) { $names = $human->getElementsByTagName( "name" ); //取得name的标签的对象数组 $name = $names->item(0)->nodeValue; //取得node中的值,如<name> </name> $sexs = $human->getElementsByTagName( "sex" ); $sex = $sexs->item(0)->nodeValue; $olds = $human->getElementsByTagName( "old" ); $old = $olds->item(0)->nodeValue; echo "$name - $sex - $old\n"; } ?> 2)simplexml读取xml<?php $xml_array=simplexml_load_file('person.xml'); //将XML中的数据,读取到数组对象中 foreach($xml_array as $tmp){ echo $tmp->name."-".$tmp->sex."-".$tmp->old."<br>"; } ?> 我这不是在读取一个xml,是从数据库读取数据并生成一个xml并显示在网页上,我在循环里如果写$dom->save('new_materials.xml');是可以正常生成xml的,可我是想显示在网页上,我用echo和print都不能实现 用echo和print都是可以的,但要保证没有其他输出。否则会因多了其他内容而造成浏览器解析失败最好还先发一个类型声明:header("Content-type: text/xml"); str_replace好像有bug open_basedir restriction in effect.问题 请教PHP语法 看不清楚程序的执行过程和程序的结构(例如php168整站系统2008版也即V5.0版) 请教如何写这样的一个SQL呢 php 数组 关于PHP问题 怎么用数据库来直接存储session啊? 子窗口操作父窗口的form域 session问题求助 谁帮忙看看 这个代码为什么不会循环 PHP 代码 在下来框判断报错
$doc = new DOMDocument();
$doc->load('person.xml'); //读取xml文件
$humans = $doc->getElementsByTagName( "humans" ); //取得humans标签的对象数组
foreach( $humans as $human )
{
$names = $human->getElementsByTagName( "name" ); //取得name的标签的对象数组
$name = $names->item(0)->nodeValue; //取得node中的值,如<name> </name>
$sexs = $human->getElementsByTagName( "sex" );
$sex = $sexs->item(0)->nodeValue;
$olds = $human->getElementsByTagName( "old" );
$old = $olds->item(0)->nodeValue;
echo "$name - $sex - $old\n";
}
?> 2)simplexml读取xml<?php
$xml_array=simplexml_load_file('person.xml'); //将XML中的数据,读取到数组对象中
foreach($xml_array as $tmp){
echo $tmp->name."-".$tmp->sex."-".$tmp->old."<br>";
}
?>
否则会因多了其他内容而造成浏览器解析失败
最好还先发一个类型声明:
header("Content-type: text/xml");