PHP Humaniser l'affichagededuréesécoulées

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Humaniser l'affichagededuréesécoulées相关的知识,希望对你有一定的参考价值。

/**Function when($ts) takes timestamp on input and returns
  * human readable time difference. Example output:
  * I am running my script in 20 minute intervals to clear the
  * database and remove overhead.
**/

function kiedy($ts) {
   $ts=time()-$ts;
   if ($ts<60)
       // <1 minute
       return $ts; //." seconds ago";
     elseif ($ts<60*60)
       // <1 hour
       return floor($ts/60); //." minutes ago";
   elseif ($ts<60*60*2)
       // <2 hour
       return "60"; //"1 hour ago";
     elseif ($ts<60*60*24)
       // <24 hours = 1 day
       return floor($ts/60*60); //." hours ago";
     elseif ($ts<60*60*24*2)
       // <2 days
       return "1 day ago";
     elseif ($ts<60*60*24*7)
       // <7 days = 1 week
         return floor($ts/60*60*24); //." days ago";
   elseif ($ts<60*60*24*30.5)
       // <30.5 days ~  1 month
       return floor($ts/60*60*24*7); //." weeks ago";
     elseif ($ts<60*60*24*365)
       // <365 days = 1 year
       return floor($ts/60*60*24*30.5); //." months ago";
   else
       // more than 1 year
       return floor($ts/60*60*24*365); //." years ago";
};

$link = mysql_connect("localhost", "database", "pwd");
mysql_select_db("database");
$res = mysql_query("SELECT timestamp from chattable ORDER by timestamp DESC");
while ($line = mysql_fetch_array($res, MYSQL_ASSOC)) {
    $ts = $line['timestamp'];
    $result=kiedy($ts);
    if ($result > 20 ) {  // ADJUST THIS TO CLEAR X MINUTES
        $SQL = "DELETE from chattable WHERE timestamp = '$ts'";
        $resultD = mysql_query($SQL);
    }
}

$SQL = 'OPTIMIZE TABLE chattable';
$resultO = mysql_query($SQL);

以上是关于PHP Humaniser l'affichagededuréesécoulées的主要内容,如果未能解决你的问题,请参考以下文章

php FuncióURLde l'API de drupal

php calcola l'etàfornitogiorno mese e anno #php #function #date

php 在una pagina archivio的recupera l'id della tassonomia corrente

php recupera la tassonomia dato l'id dell'elemento。 Restituisce un array qui prendo il primo

php wordpress Autoriser l'ajout depagesprivéesaumenu etlesmasquéspourles visiteurs ano

php Ajouter un lien de sous menu dans l'admin vers unetaxoponalnalisée