title: php convert seconds to timestamp
body: <p>I have a total seconds value in my table but I would like to get a time format like <code>hh:mm:ss</code>,
  currently I have for example: <code>seconds - 226</code> and I know that should be in time format 4 minutes and 26 seconds, but I've tried this code:</p>
  
  <pre><code>$seconds = 226;
  $hours = floor($seconds / 3600);
  $mins = floor(($seconds - ($hours*3600)) / 60); 
  $secs = floor(($seconds - ($hours*3600)) - ($mins*60));
  </code></pre>
  
  <p>and this outputs <code>3:46</code></p>
  
  <p>maybe there's something wrong with the formula?</p>
  
  <p>EDIT: I got this value from a youtube scripts that returns duration of video:</p>
  
  <pre><code>    $ytvidid = $url;
  $ytdataurl = "http://gdata.youtube.com/feeds/api/videos/". $ytvidid;
  $feedURL = $ytdataurl;
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $feedURL);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  // get the result of http query
  $output = curl_exec($ch);
  curl_close($ch);
  // feed the curl output to simplexml_load_string
  $sxml = simplexml_load_string($output) or die("XML string not loading");
  
  //$sxml = simplexml_load_file($feedURL);
  $media = $sxml-&gt;children('http://search.yahoo.com/mrss/');
  // get &lt;yt:duration&gt; node for video length
  $yt = $media-&gt;children('http://gdata.youtube.com/schemas/2007');
  $attrs = $yt-&gt;duration-&gt;attributes();
      echo $attrs['seconds'];
  </code></pre>