bateman Posted January 3, 2014 Share Posted January 3, 2014 (edited) So I've tried 6 different methods of pulling the data from the xml but each time I get nothing. I KNOW it's going to be something stupidly simple, but at the moment I'm stumpped. Here is the code I'm working with, and not that it's not complete as I still need to write in the glob code to limit the results to a single date. Edit: the print is commented because I used it to show me that the xml is reading. $date = date("Y-m-d"); //echo $fdate; $glob = "./fromdb/TimesheetBackup_" . $date. "*.xml"; foreach (glob ($glob) as $result) { echo $result; $xml = simplexml_load_file($result); $count = 0; //print_r($xml);// "<br> $xml"; foreach ($xml->tasks[] as $tasks): $starttimeb = $tasks['startDate']; $starttime = substr($starttimeb, -8, -1); $endtime = $tasks->key->endDate; echo $starttime; echo "<br> $endtime"; endforeach; } and a sample of the xml (end of a 48 record xml) <task> <taskId>f620bba390874d9fa41ddc4384ac0ba0</taskId> <projectId>7ab307cc59e84219b5e1b7b6215a7400</projectId> <description></description> <location>552 Pandora Ave, Victoria, BC V8W 1N7</location> <startDate>2014-01-02T13:15:00</startDate> <endDate>2014-01-02T16:33:00</endDate> <deleted>false</deleted> <endTime>0</endTime> <startTime>0</startTime> <lastUpdate>1388709184182</lastUpdate> <paid>0</paid> <feeling>0</feeling> </task> </tasks> </timesheet> I'm trying to get this to work with a xml that's created by the android app Timesheet. This is from it's auto backup system so I have no control over the output of the xml. Edited January 3, 2014 by bateman Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 3, 2014 Share Posted January 3, 2014 (edited) yes, but you haven't told us what the debugging echo/print_r statements showed. for all we know the glob() isn't finding any files because the path, filename, letter-case, or date format isn't correct. Edited January 3, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted January 3, 2014 Solution Share Posted January 3, 2014 try it like this foreach ($xml->tasks->task as $task) { echo $task->startDate . '<br>'; } Quote Link to comment Share on other sites More sharing options...
bateman Posted January 3, 2014 Author Share Posted January 3, 2014 the glob was showing the file names, and the foreach you posted worked, now I just need to format it for my needs (the substr and such, which I've already tested). Right now I have it outputing to the screen, but once it's done, it's going to be a cron update page. Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.