phpcode Posted December 1, 2009 Share Posted December 1, 2009 I'm trying to make a countdown page by getting the information from this websites api but I need to know how I would get it to display how many hours and minutes left. The URL is http://services.tvrage.com/tools/quickinfo.php?show=dexter&exact=1 The part I'm working on is: RFC3339@2009-12-06T21:00:00 Does anyone know how? Quote Link to comment https://forums.phpfreaks.com/topic/183519-making-a-countdown-from-websites-api/ Share on other sites More sharing options...
mikesta707 Posted December 1, 2009 Share Posted December 1, 2009 Assuming your time strings will always be of that format (and have a valid time) You could do something like this $string = "RFC3339@2009-12-06T21:00:00"; $time = end(explode('@', $string)); $time = strtotime($time); $now = time(); $timeLeft = $time - $now; $secsInDay = 60*60*24;//60 seconds in a min * 60 mins in an hour * 24 hours in a day //day sleft $daysLeft = (int)($timeLeft / $secsInDay); $timeLeft %= $secsInDay; $secsInHour = 60*60; //hours left $hoursLeft = (int)($timeLeft / $secsInHour); $timeLeft %= $secsInHour; //minutes left; $minutesLeft = (int)($timeLeft / 60);//60 secs in a minute $timeLeft %= 60; //secs left is timeLeft $secsLeft = $timeLeft; echo "$daysLeft days $hoursLeft hours $minutesLeft minutes and $secsLeft seconds"; Just ask if you need an explanation Quote Link to comment https://forums.phpfreaks.com/topic/183519-making-a-countdown-from-websites-api/#findComment-968660 Share on other sites More sharing options...
phpcode Posted December 1, 2009 Author Share Posted December 1, 2009 Thanks mikesta I'm trying to list about 10 shows and I want to know if there is any better way in doing this? This is what I've got now: <?php function get_between ($text, $s1, $s2) { $mid_url = ""; $pos_s = strpos($text,$s1); $pos_e = strpos($text,$s2); for ( $i=$pos_s+strlen($s1) ; ( ( $i < ($pos_e)) && $i < strlen($text) ) ; $i++ ) { $mid_url .= $text[$i]; } return $mid_url; } function get_time ($string) { $time = end(explode('@', $string)); $time = strtotime($time); $now = time(); $timeLeft = $time - $now; $secsInDay = 60*60*24;//60 seconds in a min * 60 mins in an hour * 24 hours in a day //day sleft $daysLeft = (int)($timeLeft / $secsInDay); $timeLeft %= $secsInDay; $secsInHour = 60*60; //hours left $hoursLeft = (int)($timeLeft / $secsInHour); $timeLeft %= $secsInHour; //minutes left; $minutesLeft = (int)($timeLeft / 60);//60 secs in a minute $timeLeft %= 60; //secs left is timeLeft $secsLeft = $timeLeft; echo "$daysLeft days $hoursLeft hours $minutesLeft minutes and $secsLeft seconds<BR><BR>"; } $rs2 = file_get_contents("http://services.tvrage.com/tools/quickinfo.php?show=lost&exact=1"); $between = get_between($rs2, "RFC3339", "GMT+0"); get_time($between); $rs2 = file_get_contents("http://services.tvrage.com/tools/quickinfo.php?show=dexter&exact=1"); $between = get_between($rs2, "RFC3339", "GMT+0"); get_time($between); ?> Quote Link to comment https://forums.phpfreaks.com/topic/183519-making-a-countdown-from-websites-api/#findComment-968678 Share on other sites More sharing options...
mikesta707 Posted December 1, 2009 Share Posted December 1, 2009 well this for ( $i=$pos_s+strlen($s1) ; ( ( $i < ($pos_e)) && $i < strlen($text) ) ; $i++ ) { $mid_url .= $text[$i]; } can be accomplished with substr <?php function get_between ($text, $s1, $s2) { $pos_s = strpos($text,$s1); $pos_e = strpos($text,$s2); return substr($text, $pos_s + strlen($s1), $pos_e - ($pos_s + strlen($s1)) ); } $text = "This will be some VEERY long text with somsde words and more words, but yeah..."; echo get_between($text, "be", "words"); ?> some VEERY long text with somsde Quote Link to comment https://forums.phpfreaks.com/topic/183519-making-a-countdown-from-websites-api/#findComment-968686 Share on other sites More sharing options...
phpcode Posted December 1, 2009 Author Share Posted December 1, 2009 Thanks mikesta Quote Link to comment https://forums.phpfreaks.com/topic/183519-making-a-countdown-from-websites-api/#findComment-968870 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.