如何在3分49秒后重定向到另一个页面
I was working on a site which plays songs using soundcloud API; what I thought is why not create a loop so that songs keep playing without bothering the user, to select different song after every song. For this what I am doing is redirect the user to page of another song once the current song completes. Soundcloud API provide me the duration of currently playing song in a PHP variable I am using that variable in http-redirect but the problem is what happens when a song with duration 3minutes and 49 seconds is playing how to convert that into seconds. Because http-redirect works on seconds and not on minutes. If I use 3.49 * 60 that will make it 209.4 but actually 3 minutes and 49 seconds have 229 seconds.
我正在使用soundcloud API播放歌曲的网站; 我的想法是为什么不创建一个循环,以便歌曲在不打扰用户的情况下继续播放,在每首歌曲之后选择不同的歌曲。 为此,我正在做的是在当前歌曲完成后将用户重定向到另一首歌的页面。 Soundcloud API为我提供PHP变量中当前播放歌曲的持续时间我在http-redirect中使用该变量,但问题是当持续时间为3分钟和49秒的歌曲正在播放如何将其转换为秒时会发生什么。 因为http-redirect在几秒钟而不是在几分钟内工作。 如果我使用3.49 * 60将使其成为209.4但实际上3分49秒有229秒。 p> div>
What about this:
<?php
// $length is the length of the song
$length_array = explode('.', $length);
$seconds = $length_array[0] * 60 + $length_array[1];
// ... redirect after $seconds ...
That cuts the string into 2 pieces, the first one is the amount of minutes (that are multiplied by 60 to get the amout of seconds) and the second one is the amount of seconds.
See explode
to learn more.
Hope this helps.