Advertisement
Guest User

function postrev_wordcount

a guest
Dec 6th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?
  2. function postrev_wordcount ()
  3.     {
  4.     global $db, $db_prefix , $config_data, $dir;
  5.     include($dir."language/".$config_data["lang"].".php");
  6.  
  7.     // traigo todo el texto de cada noticia más el año
  8.     $consulta_noticias = "select year(time) as anio, hometext, bodytext from".$db_prefix." posts where estado = 1;";
  9.    
  10.     $contador = array("2002" => 0, "2003" => 0, "2004" => 0, "2005" => 0, "2006" => 0, "2007" => 0, "2008" => 0, "2009" => 0, "2010" => 0, "2011" => 0); // total palabras
  11.     $contador2 =  array("2002" => 0, "2003" => 0, "2004" => 0, "2005" => 0, "2006" => 0, "2007" => 0, "2008" => 0, "2009" => 0, "2010" => 0, "2011" => 0); // cantidad de posts
  12.     print_r($contador);
  13.    
  14.     $resultado = $db->sql_query($consulta_noticias);
  15.     while ($row = $db->sql_fetchrow($resultado))
  16.         {
  17.         $anio = $row[anio];
  18.         $bodytext = strip_tags($row[bodytext]);
  19.         $hometext = strip_tags($row[hometext]);
  20.         $total = str_word_count($bodytext) +  str_word_count($hometext);
  21.         $contador[$anio] = $contador[$anio] + $total;
  22.         $contador2[$anio] = $contador2[$anio] + 1;
  23.         }
  24.    
  25.     print_r($contador);
  26.     print_r($contador2);
  27. }
  28. ?>
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement