Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

PHP : Hace Script / Ago Script

Hace Script / Ago Script
if we call with a timestamp of a month ago, he print "Hace 1 mes". If you want this in english should traduction. Sorry my english

   1  
   2  function hace($timestamp)
   3  {
   4  $diferencia = time() - $timestamp;
   5  	if($diferencia > 0)
   6  	{
   7  $periodo = array("segundo", "minuto", "hora", "dia", "semana", "mes" , "año", "decada");
   8  $longitud = array(           "60"    , "60"  , "24" , "7"     , "4.35", "12"       , "10"    );
   9  	
  10  	for($j = 0; $diferencia >= $longitud[$j]; $j++)
  11  	$diferencia /= $longitud[$j];
  12  	
  13  	$diferencia = round($diferencia);
  14  	
  15  	if($diferencia != 1)
  16  	{
  17  		if($periodo[$j] == "mes")
  18  		$periodo[$j].= "es";
  19  		else
  20  		$periodo[$j].= "s";
  21  	}
  22  	
  23  	return "Hace <b>".$diferencia."</b> ".$periodo[$j];
  24  	}
  25  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS