Pedro Chagas
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
$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>";
ASKER
For help:
The variable $coleta_keywords_final contains "holiday$ in portugal, villa, alga1111rve holidays, algarve villa, villas in portugal, sun, black"
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
Best, ~Ray
ASKER
Ray, do you have the link for that post?
Regards, JC
Regards, JC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
$string = "holiday$ in portugal, villa, alga1111rve holidays, algarve villa, villas in portugal, sun, black";