SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: PHP/XML Problem

  1. #1
    SitePoint Zealot
    Join Date
    Oct 2010
    0 Post(s)
    0 Thread(s)

    PHP/XML Problem

    Hi people!

    I'm having a little trouble getting an XML file to load & display correctly using PHP. I've been able to do it with all my other XML Reports so far, but this one is structured a little differently to how I'm used to so I'm not sure how to go about calling up the relevant objects within the XML file.

    The full URL of the XML File is:

    Please note, the two parts in red (the date). I am using the below PHP code to automatically update this URL and load the current XML File for today's date.

    Code PHP:
    $today = date ('m/d/Y');
    $file = '' . urlencode($today) . '&DateTo=' . urlencode($today) . '&ReportFormat=XML&NewsFlash=&AccountID=Neosis&AppID=CDS&MemberID=1234567890&V=2';
    $xml = simplexml_load_file($file);

    That part, I'm comfortable with - I've used the same method to connect to all of my remote XML Files for daily content and it works perfectly... The next part is where I am trying to tell the page which objects from the XML file I want to display and that is what I'm having trouble with.

    The Full XML structure is as follows:

    Code XML:
    Some Content Here
    Some More content Here

    I want to display just the part where it says "Some more content here" - so that's the part wrapped in the "astroweatherlong" tags.

    The problem I am having seems to have something to do with the "date-20110318" tag, which I assume is a parent to the tag that I am actually trying to fetch. It seems that because it has the word "date" in it, I need to call it differently somehow. Also, because it needs to be the "current" date, I need that to change like the date in the URL does.

    I've tried the following variations but neither of them are working:

    Code PHP:
    $reportdate= date ('Ymd');
    <?php echo $xml->dailyintros->date-$reportdate->astroweather->astroweatherlong; ?>
    <?php echo $xml->dailyintros->'date-$reportdate'->astroweather->astroweatherlong; ?>
    <?php echo $xml->dailyintros->'date'-$reportdate->astroweather->astroweatherlong; ?>

    I even tried it using the actual tag that is shown above (the full date-20110318) but that didn't work either. It has to be something to do with the word "date" with that being a PHP function itself...

    Can someone please tell me how to call this section of the XML file and make it so that it always calls "today's" one?


  2. #2
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    0 Post(s)
    0 Thread(s)
    PHP Code:
    $file '' urlencode($today) . '&DateTo=' urlencode($today) . '&ReportFormat=XML&NewsFlash=&AccountID=Neosis&AppID=CDS&MemberID=1234567890&V=2';
    $xml simplexml_load_file($file);
    $reportdate date('Ymd');
    $dateTag 'date-'.$reportdate;

    I'm not sure where you were getting the 'dailyintros' tag because that doesn't seem to be part of the xml from that url. - PHP articles and more

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2010
    0 Post(s)
    0 Thread(s)
    aamonkey, you are a star! thank you


Posting Permissions

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