Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Aug 2008
    Posts
    36
    Tokens
    0

    Default PHP variables added to XML

    Basically i have a XML file which i read from for e.g.

    Code:
    <person>
          <firstName> tom</firstName>
    </person>
    now is it possible to make the first name data read from a php variable say for e.g.

    PHP Code:
    $firstname "tom"
    Code:
    <person>
          <firstName> tom</firstName>
                           // so variable <firstName> is always saved as childNodes [i][0]
    </person>
    Is this possible :S?

  2. #2
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    <?php
    $file = file_get_contents( "xmlfile.xml" );
    $file = explode( "<firstName>" , $file);
    echo $file[0];
    ?>
    Lets set the stage on fire, and hollywood will be jealous.

  3. #3
    Join Date
    Aug 2008
    Posts
    36
    Tokens
    0

    Default

    yeah i know how to retrieve data from a XML file, but what i want is to write data into the XML file but storing it as a php variable rather than a XML variable.

    Like say i have in my php page a variable named $name i want to be able to put whatever is stored in that PHP variable into the XML file.

  4. #4
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    fwrite?
    Coming and going...
    Highers are getting the better of me

  5. #5
    Join Date
    Aug 2008
    Posts
    36
    Tokens
    0

    Default

    yeah but how would i be able to write in a specific place in the XML file without deleting what already in there?

  6. #6
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    find 'tom', replace it with 'god'...
    Hi, names James. I am a web developer.

  7. #7
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Do this..

    PHP Code:
    <?php

    $name 
    "Caleb";

    $xml .= "<blah>";
    $xml .= "<name>" $name "</name>";
    $xml .= "</blah>";

    header("Content-type: text/xml");

    echo 
    $xml;

    ?>
    Then just use mod_rewrite to rewrite that to blah.xml or something.

  8. #8
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    PHP Code:
    <?php

    $exampleXML 
    '    <persons>
                        <dude>James</dude>
                        <dude>Celeb</dude>
                        <dude>Mark</dude>
                        <dude>God</dude>
                    </persons>'
    ;

    $xmlExplode explode'<persons>'$exampleXML );
    $xmlPersons str_replace'</persons>'''$xmlExplode] );

    $xmlExplode explode'<dude>'$xmlPersons );


    $xmlCeleb str_replace'</dude>'''$xmlExplode] );
    $xmlJames str_replace'</dude>'''$xmlExplode] );

    echo( 
    $xmlCeleb );

    ?>
    Something maybe around that?
    Hi, names James. I am a web developer.

  9. #9
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Why not just use SimpleXML?

  10. #10
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    I was gonna recommend SimpleXML aswel.


    www.fragme.co = a project.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •