Re: Extracting Numbers from a string.

From: Date: Wed, 11 Sep 2002 23:52:18 +0000
Subject: Re: Extracting Numbers from a string.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-116056@lists.php.net to get a copy of this message
A simple: eregi_replace("[^0-9]", "", $myvar); should do it. it says.. replace everything that is not a number ( character class "[^0-9]" which means Character class "[" NOT "^" of Decimal "0-9" end character class "]" ) with a NULL string, thereby ripping out all non-numeric components and leaving you with a totally numeric string. ( in theory ). I haven't tested the code so you may have to play with it, but it's pretty simple. dan On Wed, 11 Sep 2002 15:31:22 -0700 "Jason Caldwell" <jason@thinkingman.org> wrote: > I need to extract the numbers only from a field. > > For example: I have an AMOUNT field and so that I can filter out any user > typo's I would like to extract the numbers only. > > If the user enters $56.55 for example or just $56 then I would like to be > able to remove the "$" and the "." keeping just the 56 or 5655. > > Can I use eregi_replace() to do this -- I've been trying but it doesn't seem > to work right. > > Thanks. > Jason > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#116056) next »