-1

XML File;

 <programme channel="cnn.info" start="20131027060000" stop="20131027061500">
 <title>hello CONTENT</title>
 <premiere/></programme>

"Start" & "stop" (in xml) should be done to calculate the time difference between clocks?

For example:

Title: hello.. 
Time:left 24 minutes

xml file with the data in the calculation of the time, how can be done?

Simon Groenewolt
  • 10,607
  • 1
  • 36
  • 64
bitmez4
  • 5
  • 10

2 Answers2

1

Should be aiming for something like this:

$string = <<<XML
 <programme channel="cnn.info" start="20131027060000" stop="20131027061500">
 <title>hello CONTENT</title>
 <premiere/></programme>
XML;

$xml = simplexml_load_string($string);

$start = $xml->attributes()->start;
$stop = $xml->attributes()->stop;
$title = $xml->title;
$datetime1 = new DateTime($start);
$datetime2 = new DateTime($stop);
$interval = $datetime1->diff($datetime2);
echo "Title: " . $title . "\n";
echo $interval->format('Time left: %i minutes');

Output:

Title: hello CONTENT
Time left: 15 minutes

http://3v4l.org/gDPTQ

Ben Fortune
  • 31,623
  • 10
  • 79
  • 80
0
$xml = simplexml_load_file("filename.xml");

echo $xml->programme->title . "<br />";
echo "Time: left" . $time_left;

$time_left will be the stop date minus the start date, then convert it to a php date.

Also read this topic: Php get how many days and hours left from a date

Community
  • 1
  • 1
Joran Den Houting
  • 3,149
  • 3
  • 21
  • 51