Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- function postrev_wordrepeat(){
- global $db, $db_prefix , $config_data, $dir;
- include($dir."language/".$config_data["lang"].".php");
- $wordCounter=array();// contador de palabra-repeticion
- // traigo todo el texto de cada noticia más el año
- $consulta_noticias = "select hometext, bodytext from".$db_prefix." posts where estado = 1;";
- $resultado = $db->sql_query($consulta_noticias);
- while ($row = $db->sql_fetchrow($resultado))
- {
- $bodytext = strip_tags($row[bodytext]);
- $hometext = strip_tags($row[hometext]);
- $text = $hometext . $bodytext; // acumulo los textos
- $text = strip_tags($text);//afuera html
- $text = mb_strtolower($text,'UTF-8'); // a minusculas respetando utf-8
- $text = str_replace (array('\r\n', '\n', '+'), ',', $text);// bajadas de línea
- $text = str_replace (array('–','(',')',':','.','?','!','_','*','-', '¿', '|','¡'), '', $text);//caracteres no válidos
- $text = str_replace (array(' ','.'), ',', $text);//comas
- $arrText=explode(",",$text);//array con todas las palabras del post
- unset($text);
- foreach ($arrText as $value) {
- $value=trim($value);//saco espacios
- if ( strlen($value)>0 ) {//no menores a 1
- if (array_key_exists($value,$wordCounter)){//si existe agregamos uno a la clave existente
- $wordCounter[$value]=$wordCounter[$value]+1;
- }
- else $wordCounter[$value]=1;//crear la clave en el array
- }
- }
- }
- unset($arrText);
- uasort($wordCounter, 'cmp');//ordeno de mayor a menor
- $keywords="<ol>";
- foreach($wordCounter as $key=>$value){
- $keywords.="<li>".$key." => ".$value."</li>";
- }
- $keywords.="</ol>";
- unset($wordCounter);
- echo $keywords;
- }
- function cmp($a, $b) {//orden descendente
- if ($a == $b) return 0;
- return ($a < $b) ? 1 : -1;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement