only numbers

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

only numbers

Post by shiznatix »

ok so I was looking around and could not find it. I need to preg_replace everything but numbers 0-9 so the string can contain as many numbers as they want but no other characters but numbers. I know its like '/\d^[a-z]/i' or somthing but that would not cover the other characters out there. how do I do this?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

what are you trying to do?

Just check that all the characters in a string are numbers?

Or removing any non-numeric characters?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

removing all non-numeric numbers but i want to check if those strings where changed in the first place so i guess it will be a combo of preg_match and preg_replace
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Code: Select all

preg_replace("/[^0-9]/", "", $search_string);
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

haha thanks, I was thinking to hard on somthing so simple.
Post Reply