Link to home
Start Free TrialLog in
Avatar of Pedro Chagas
Pedro ChagasFlag for Portugal

asked on

Remove words with numbers from a long string

Hi, I have a string and inside this string I collect some phrases like:
$string = "holiday$ in portugal, algarve villa, alga1111rve holidays, algarve villa, villas in portugal,";
I want to remove the words like holiday$ and alga1111rve, and after I remove that words I get the string again preserving the commas(,), like:
$string = "in portugal, algarve villa, holidays, algarve villa, villas in portugal,";

Inside snipped code, you can see my script, but in final $coleta_keywords_final is empty!!!!!
Attention:  $coleta_keywords_final, the string have allways data formated like "in portugal, algarve villa, holidays, algarve villa, villas in portugal,".

What I do wrong?

Regards, JC
$keep = explode(',', $coleta_keywords_final); 
$coleta_keywords_final = implode(" , ", $keep);
$words = explode(',',$coleta_keywords_final);
$result = array();
foreach($words as $word)
if(!eregi('[^a-z]',$word) or 
!eregi('[^0-9]',$word)) 
$result[]=$word;
$coleta_keywords_final = implode(',',$result);
echo "<br> $coleta_keywords_final <br>";

Open in new window

Avatar of Pedro Chagas
Pedro Chagas
Flag of Portugal image

ASKER

Somethimes the string can be too:
$string = "holiday$ in portugal, villa, alga1111rve holidays, algarve villa, villas in portugal, sun, black";
For help:
The variable $coleta_keywords_final contains "holiday$ in portugal, villa, alga1111rve holidays, algarve villa, villas in portugal, sun, black"
You can look at each word selectively.  I will post an example that does this.

Best, ~Ray
Ray, do you have the link for that post?

Regards, JC
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial