Jump to content

I want to get the numbers only and omit the commas


Jarod

Recommended Posts

Well I give up on this... Even though I learned a lot about regex, but forget it... Anyways, I've been trying to figure out how I would handle my inputs so that it only looks at the numbers and nothings else.

 

Check out 900,000,000,000 for example (900 billions btw). I enter it exactly as, but when it comes down for processing it I only want the numbers to go through, which would be 900000000000. I've heard of regex before, but never actually understood its purpose and how its suppose to be used. So anyways I used the expressions /[0-9]{1,3}[^,]*/, but the problem of that is I cant get it to only look at the numbers (omitting the commas and only using the numbers). Its array would output

 

Array [0] (

$match[0] = 900;

$match[1] = 000;

$match[2] = 000;

$match[3] = 000;

)

 

Any way I can get it to look at the string like this??? (900000000000)

You could use more basic string functions instead, for example:

str_replace(',', '', '900,000,000,000')

 

If you want to use a regular expression, the following simply removes all commas:

preg_replace('/,/', '', '900,000,000,000')

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.