Php 如何在xml中存储数据?
我有一个php文件,其中我通过以下代码显示xml文件的数据Php 如何在xml中存储数据?,php,xml,Php,Xml,我有一个php文件,其中我通过以下代码显示xml文件的数据 <?php $xml = simplexml_load_file("note.xml") or die("Error: Cannot create object"); foreach($xml->xpath('//agent') as $item) { $row = simplexml_load_string($item->asXML()); $v = $row->xpath('
<?php
$xml = simplexml_load_file("note.xml") or die("Error: Cannot create object");
foreach($xml->xpath('//agent') as $item) {
$row = simplexml_load_string($item->asXML());
$v = $row->xpath('//id[. ="1"]');
if($v[0]){
print $item->id;
print $item->image;
print $item->name;
print $item->company;
print $item->street;
print $item->city;
print $item->phone;
}
else{
echo 'No records';
}
?>
在第一个文档中启动您的会话
<?php
session_start();
$xml = simplexml_load_file("note.xml") or die("Error: Cannot create object");
foreach($xml->xpath('//agent') as $item) {
$row = simplexml_load_string($item->asXML());
$v = $row->xpath('//id[. ="1"]');
if($v[0]){
print $item->id;
print $item->image;
print $item->name;
print $item->company;
print $item->street;
print $item->city;
print $item->phone;
}
else{
echo 'No records';
}
$name = $_session['name'][$item->name]; // dont quote ''
?>
您的会话代码无效,您可以尝试此代码
$name=$\会话['name'][$item->name]
<?php
session_start();
$xml = simplexml_load_file("note.xml") or die("Error: Cannot create object");
foreach($xml->xpath('//agent') as $item) {
$row = simplexml_load_string($item->asXML());
$v = $row->xpath('//id[. ="1"]');
if($v[0]){
print $item->id;
print $item->image;
print $item->name;
print $item->company;
print $item->street;
print $item->city;
print $item->phone;
}
else{
echo 'No records';
}
$name = $_session['name'][$item->name]; // dont quote ''
?>