Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在xml中存储数据?_Php_Xml - Fatal编程技术网

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文件的数据

<?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 ''
?>