• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

Remove words with numbers from a string

Hi, I try to remove some words from a string, and I need some help.
I want remove words whit numbers, like paa034000060, and remove words whose content is not a-z or 0-9, like &exp.
If I have the string:
$string = "the world is12 round and blu&";

After I want a string like:
$string = "the world round and";

Regards, jc
Pedro Chagas
Pedro Chagas
  • 2
  • 2
1 Solution
I suppose you could use:

ereg_replace although it doesn't seem very efficent

Do something like this:
$string = "abcd123#$%";
$string = ereg_replace("0", "", $string);
$string = ereg_replace("1", "", $string);
$string = ereg_replace("2", "", $string);

Open in new window

Or, you could pass the string through javascript which has a much easier way of doing this.  I guess it just depends on what you want to do with the string when your done?
Pedro ChagasWebmasterAuthor Commented:
After this, the string go to data base!
Attention, I want erase or remove the words that no contain a-z or 1-2. Preserve words like glass, painter and 888, erase words like glass11, glas55s, %painter" or paint&er.
Roger BaklundCommented:
Try this:
$words = explode(' ',$string);
$result = array();
foreach($words as $word)
  if(!eregi('[^a-z]',$word) or 
$string = implode(' ',$result);
echo $string;

Open in new window

Pedro ChagasWebmasterAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now