<?php
function normaliza ($string){
$a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ';
$b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyyby';
$string = utf8_decode($string);
$string = strtr($string, utf8_decode($a), $b);
$string = strtolower($string);
return utf8_encode($string);
}
function parseStopWords($text){
$text = normaliza($text);
$text = str_replace(array('¡', '¿', '?', '!'), '', $text);
$text = preg_replace('/[^a-zA-Z0-9áéíóúñÁÉÍÓÚÑ¡¿\', ]/i','',$text);
$stopwords = array('ante','bajo','cabe','con','contra','de','desde','en','entre','hacia','hasta','para','por','sin','sobre','tras','el','lo','la','los','las','un','unos','una','al','del','que','es','se','y','fue');
foreach($stopwords as $w){
$text = preg_replace('/\b'.$w.'\b/i','',$text);
}
$text = preg_replace('/\s{2,}/i',' ',$text);
$text = str_replace(" a ", "", $text);
return $text;
}
echo parseStopWords('¿Qué ha sido de nuestra niñez?');
preferences:
40.81 ms | 402 KiB | 5 Q