Jump to content

XML


geniuscapri

Recommended Posts

Here's example, but it's really badly coded :-P

 

<?php
$username = 'hideous';
$countryname = 'Antarctica';
$age = 99;
  
$filename = 'userdata.xml';
  
$tmp = <<<DELIMITER
<?xml version="1.0" encoding="UTF-8"?>
<user>
  <name>$username</name>
  <country>$countryname</country>
  <age>$age</age>
</user>
DELIMITER;

$xml = simplexml_load_string($tmp);
file_put_contents($filename, $xml->asXml());
?>

Link to comment
https://forums.phpfreaks.com/topic/97764-xml/#findComment-501037
Share on other sites

This is My XML Code!

<users_acounts>
<user_info>
<username>asdfasd</username>
<password>fasd</password>
<firstname>fasdf</firstname>
<lastname></lastname>
<email></email>
<mail_stop></mail_stop>
<phone></phone>
  <permission>
	<readonly>no</readonly>
	<img_manager>no</img_manager>
	<doc_share>no</doc_share>
	<CPX>no</CPX>
  </permission>
</user_info>

<user_info>
<username>fhjfgjhfg</username>
<password>jhfgjhfg</password>
<firstname>jhfgjhfghj</firstname>
<lastname></lastname>
<email></email>
<mail_stop></mail_stop>
<phone></phone>
  <permission>
	<readonly>no</readonly>
	<img_manager>no</img_manager>
	<doc_share>no</doc_share>
	<CPX>no</CPX>
  </permission>
</user_info>
</users_acounts>

 

and This is my PHP Code

    <?php 
$file = 'testFile.xml';
if (file_exists($file)) {
// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");
$userinfo_tag=$xml->user_info;
foreach($userinfo_tag as $userinfo_tag2)
{
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");
$username_tag=$userinfo_tag2->username;
foreach($username_tag as $un_value)
{
echo $un_value;
}	?>

 

every thing is working. now want to edit any some values who's between <user_info> </ user_info> tags.

now start my problem  >:(

i am going to send user_info as ref to another page for edit my xml data.

i am doing this with.

<a href="user_edit.php?userinfo=<?php echo $userinfo_tag2;?>">Edit</a>

But $userinfo_tag2 is not going to my next page.

now Rovas can you help me??? 

Link to comment
https://forums.phpfreaks.com/topic/97764-xml/#findComment-501215
Share on other sites

SimpleXML is great for reading xml documents but if you're planning on editing XML docs then you should probably use DomDocument(). I believe it's still the defacto in PHP5+, although i'm hoping it'll change soon.

 

In fact having just checked as of 5.1.3 PHP now allows the creation of child nodes using simpleXML. WHOOP!

Link to comment
https://forums.phpfreaks.com/topic/97764-xml/#findComment-503019
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.