Ver Mensaje Individual
  #3 (permalink)  
Antiguo 02/08/2009, 14:40
cyberpasta
 
Fecha de Ingreso: marzo-2007
Mensajes: 8
Antigüedad: 17 años, 2 meses
Puntos: 0
Respuesta: Lista de palabras clave se corta en caractares especiales

Ahora si puedo postear el código:

La función clean() la uso exactamente igual para la obtención de la metadescripción y retorna correctamente el texto con los caracteres especiales por lo que deduzco que el problema está en la función keys().

Código:
function keys($text,$listexclude,$listgoldwords,$mindensity,$minlength,$maxwords) {
     $text=clean($text);
     $text = strtolower($text);

    $words_count=str_word_count($text);
    
    $array_words=array($text);

    $v=strlen($text); 

    $frequency = array_count_values( str_word_count( $text, 1) );
    arsort ($frequency);
    $words = array();
    $countwords=0;
    foreach( $frequency as $F => $value ) {

    $density = round( ($value * 100) / ($words_count) );

    $frequent_word=trim($F);
   $excludewords = @explode ( ",",$listexclude);
   if ($frequent_word!=in_array($frequent_word,$excludewords) && !in_array($frequent_word,$words)) {
   
      $includewords = @explode(",",$listgoldwords);
    //  Excluir palabras poco frecuentes, inferiores a un minimo e incluir las que esten en la lista gold
    if($value >=$mindensity || in_array($frequent_word,$includewords)){

    // Obtener la longitud de la cadena de frecuencia
    $long=strlen($F);

    //  Excluir palabras con longitud de frecuencia inferior al minimo e incluir las que esten en la lista gold
    if($long>= $minlength || in_array($frequent_word,$includewords)){
     $words[]=$frequent_word;
     $countwords++;
     if ($countwords>$maxwords)break;
     }
    }
   }
 }
 $keywordslist = implode(',',$words);
 return $keywordslist;
}

function clean($text) {
    		$text = preg_replace( "'<script[^>]*>.*?</script>'si", '', $text );
		$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text );
		$text = preg_replace( '/<!--.+?-->/', '', $text );
		$text = preg_replace( '/{.+?}/', '', $text );
		$text = preg_replace( '/&nbsp;/', ' ', $text );
		$text = preg_replace( '/&amp;/', ' ', $text );
		$text = preg_replace( '/&quot;/', ' ', $text );
		$text = strip_tags( $text );
		$text = htmlspecialchars( $text );
             $text = str_replace(array("\r\n", "\r", "\n", "\t"), " ", $text);
        		while (strchr($text,"  ")) {
			$text = str_replace("  ", " ",$text);
		}
	for ($cnt = 1; $cnt < strlen($text)-1; $cnt++) {
			// add a space after any full stops or comma's for readability
			// added as strip_tags was often leaving no spaces
			if (($text{$cnt} == '.') || ($text{$cnt} == ',')) {
				if ($text{$cnt+1} != ' ') {
					$text = substr_replace($text, ' ', $cnt + 1, 0);
				}
			}
		}
	return $text;
 }