I have a question about how to get the first 2 or 3 words of a sentence. For example:
Example_1:
$text_1 = "Chaleco azul con tejido algodón";
Resultado=> Chaleco azul
Example_2:
$text_2 = "Lampara de lectura para la cama";
Resultado=> Lampara de lectura
Example_3:
$text_3 = "Suave oso de peluche de color morado";
Resultado=> Suave oso peluche
If you notice sometimes you can take the "DE", as in the example 2, instead in the example 3 it does not take the "DE". I do not know how the letters "DE" can be discriminated.
I say ... If the next word is more than 4 characters, add it otherwise do not suppress the remaining words ...
Thanks in advance
Forgive me, for having explained me so badly. I detail the idea better and with more examples, and thanks for the quick answers. ;)
The idea is to always get the first 3 words, except when in the 3rd position there is an "DE". In which case we would include the word that occupies the 4th position.
$Ejemplo_1= "zapatillas de fútbol para correr";
Resultado_1=> zapatillas de fútbol
As you can see in Result_1, we always rescue the first 3 words. In this case the "DE" does not end in the 3rd position, therefore the result would be OK.
$Ejemplo_2= "15 metros de lona para el restaurante";
Resultado_2: 15 metros de lona
In the Result_2, if you look at the 3rd Position ends with a "DE", therefore the requirement mentioned above is met. Therefore we will only take the next word that is in the 4th position.
$Ejemplo_3= "Tarjeta memoria kodak 15 fotografías HD";
Resultado_3: Tarjeta memoria kodak
In Result_3, only take the 3 words, since it does not contain any "DE".