Filter connection words for phrase elements

0

I'm trying to make a word filter in a string, to store in a variable.

Grammatically, they are called prepositions , circumposiciones and postpositions .

Used to link elements of a phrase.

EX:

$string = "o rato roeu a roupa do rei de roma"  
//aqui a função armazenando as palavras filtradas, que eu acredito que seja um array  
$novoValor = "rato roeu roupa rei roma;  
echo $novovalor; 
    
asked by anonymous 08.12.2015 / 17:09

1 answer

0

Use in_array to check if the word you want to remove exists.

$string = "o rato roeu a roupa do rei de roma"  ;

$frase = explode(' ',$string);
$retirar = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U", "de", "do");

for($x=0;$x<count($frase);$x++){
    if(!in_array($frase[$x], $retirar)){ 
        $novovalor .= $frase[$x].' ';
    }
}

echo $novovalor;
    
08.12.2015 / 17:19