By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

xml and php

luke14free
P: 79
Hello,
I am working for a web syte and i would like to interact with some xml datas but i don't know if it's possible. I have something like that:

data.xml

Expand|Select|Wrap|Line Numbers
  1. <objcts>
  2.   <obj>
  3.     <title>1</title>
  4.     <name>2</name>
  5.     <notice><![CDATA[some data]></notice>
  6.   </obj>
  7. <objcts>
  8.  
And i need to add new objects and objects' attributes(at the obj level) like the existing one with some forms.
By now i understood that i need one of those:
1) a way to interact with xml in some way(that i dont know)
2) a way to search in my file the first '<ev>' occurrence ,then put inside the new object in the file and finally close it.

I am new to PHP so everything could help!

Regards & thanks,
luke14free
May 22 '07 #1
Share this Question
Share on Google+
1 Reply


luke14free
P: 79
solved thanks...Thats the code I used...
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $notice="ciao!";//$_POST['notice']
  3. $aut="me!";//$_POST['autore']
  4. $ogg="cool!";//$_POST['ogg']
  5. $myFile = "file.xml";
  6. $fh = fopen($myFile, 'r+');
  7. $theData = fread($fh, filesize($myFile));
  8. $file1=ereg_replace("<events>"," ",$theData);//erase the <event> tag
  9. $file=ereg_replace("</events>"," ",$file1);//erase the </event> tag
  10. $tmp="<event>\n<notice><![CDATA[".$notice."]]></notice>\n<nick>".$aut."</nick>\n<oggetto>".$ogg."</oggetto>\n</event>\n";
  11. $tw="<events>\n".$tmp."\n".$file."\n</events>\n";
  12. fclose($fh);
  13. $fh2 = fopen($myFile, 'w');
  14. fwrite($fh2,$tw);
  15. fclose($fh2);
  16. ?>
  17.  
BTW thanks :D
May 22 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.