Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Form Submission to xml

  • 09-01-2007 10:23PM
    #1
    Closed Accounts Posts: 493 ✭✭


    Hi,

    Im new to the whole php creation. However, i have created a site which reads information from an xml file and shows it on screen.

    I now want to create a page which allows the user to fill in a form (headline and body for example) and when they choose submit it gets written to the xml file.

    Any ideas on a simple structure?


Comments

  • Registered Users, Registered Users 2 Posts: 568 ✭✭✭phil


    It does really depend I guess whether this information needs to conform to a DOM, but in general writing XML is much easier than reading it.

    PHP uses a SAX based parser for reading/writing XML, but you can simply use good ol' print to write it :) (the third option is to use the DOM)

    First of all I guess is to tell us whether you're using a procedural style of PHP or OO (OO - class based ; procedural - linear function based)

    Second is the version of PHP you're using, PHP 4.x or PHP 5.x (or God forbid PHP 3.x)

    Writing XML can be done with good 'ol print i.e.
    $xml_write =<<<EOXML;
    <?xml version='1.0' encoding='utf-8'?>
    <car>
       <make> BMW </make>
       <model> 318 </model>
       <engine> 1.8 </engine>
    </car>
    EOXML;
    


    The $xml_write variable can now be written to screen or to a file to output an XML "file".

    e.g.
    $fp = fopen("test.xml", "w")
    fputs($fp, $xml_write);
    fclose($fp);
    

    I'm not 100% that the code is syntactically correct, treat it as pseudo-code until you test it yourself :)

    We can be more specific if you tell me the information above.

    Phil.


Advertisement