PHP and XML

Discussion in 'PHP' started by mnymkr, Aug 30, 2007.

  1. #1
    I am trying to make a simple script that choose a new xml entry every time the page is refreshed. you can think of it as an php/xml banner rotator...

    any ideas on this?
     
    mnymkr, Aug 30, 2007 IP
  2. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #2
    to what end?
    if you provide more information someone might be able to help.

    i.e.
    why is it in xml?
    why would you want a new xml entry on every refresh? after X hits you will have a huge file
     
    m0nkeymafia, Aug 30, 2007 IP
  3. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #3
    sorry i should be more clear.

    i am trying not to pull from a database

    so say i have an xml file that has two text areas of code

    I want a php script that will read the first text area and present that code and then on refresh present the next text area of the xml file
     
    mnymkr, Aug 30, 2007 IP
  4. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #4
    ahh right ok
    well AFAIK the only way to pull xml data is using SAX, its kinda difficulty to understand but basically it iterates through each section in the XML and offers you the chance to deal with it.

    It might be better, in your case, to write a simple regex to pull out the data. Then use a random number to decide which one to pull.

    I.e. if you preg_match_all the data and it finds 2 matches [thatll be your two lots of text] itll return an array of the two text, simply create a random number between 0 and N-1 [where N is the number of matches] and your sorted!
     
    m0nkeymafia, Aug 31, 2007 IP