Jump to content


Photo

Removing numbers from a string


  • Please log in to reply
2 replies to this topic

#1 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 02 June 2006 - 08:41 AM

Hiya, could anyone tell me the best way to remove numbers from a text string please? I think it's using explode, but i don't remember the correct syntax and can't seem to find an example anywhere.

The string is coming from a database (dunno if this makes a difference).

thanks.
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 02 June 2006 - 08:47 AM

$string = "abc123abc";
$new_str = preg_replace("/[0-9]+/i","",$string);
echo $new_str;
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 02 June 2006 - 12:43 PM

thanks very much ;-)
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users