xml and php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luke14free
    New Member
    • Apr 2007
    • 79

    xml and php

    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

    [CODE=xml]
    <objcts>
    <obj>
    <title>1</title>
    <name>2</name>
    <notice><![CDATA[some data]></notice>
    </obj>
    <objcts>
    [/CODE]
    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
    Last edited by pbmods; May 23 '07, 03:46 AM. Reason: Changed code language. Thanks for using CODE tags!
  • luke14free
    New Member
    • Apr 2007
    • 79

    #2
    solved thanks...Thats the code I used...
    [CODE=php]
    <?php
    $notice="ciao!" ;//$_POST['notice']
    $aut="me!";//$_POST['autore']
    $ogg="cool!";//$_POST['ogg']
    $myFile = "file.xml";
    $fh = fopen($myFile, 'r+');
    $theData = fread($fh, filesize($myFil e));
    $file1=ereg_rep lace("<events>" ," ",$theData) ;//erase the <event> tag
    $file=ereg_repl ace("</events>"," ",$file1);//erase the </event> tag
    $tmp="<event>\n <notice><![CDATA[".$notice."]]></notice>\n<nick> ".$aut."</nick>\n<oggetto >".$ogg."</oggetto>\n</event>\n";
    $tw="<events>\n ".$tmp."\n".$fi le."\n</events>\n";
    fclose($fh);
    $fh2 = fopen($myFile, 'w');
    fwrite($fh2,$tw );
    fclose($fh2);
    ?>
    [/CODE]
    BTW thanks :D
    Last edited by pbmods; May 23 '07, 03:47 AM. Reason: Changed code language. Thanks for using CODE tags!

    Comment

    Working...