|
-
Apr 21st, 2010, 02:07 PM
#1
Thread Starter
Hyperactive Member
Remove all non digit characters
How can I take a string and remove all non digit characters from the string? Unfortunately my regex skills arent so hot
-
Apr 21st, 2010, 02:35 PM
#2
Thread Starter
Hyperactive Member
Re: Remove all non digit characters
This seems to be working well:
Code:
$str = "1234567890abc!@#$%^&*()-=_+[]{}|\\'\"?/><,.";
echo preg_replace("%[^0-9]%", "", $str);
Any objections?
-
Apr 21st, 2010, 09:27 PM
#3
Re: Remove all non digit characters
No objections. You can use \d as well as 0-9.
-
Jun 7th, 2010, 08:12 PM
#4
Thread Starter
Hyperactive Member
Re: Remove all non digit characters
how do i turn this into a preg_match?
I need to match if a string is all digits, if so true else false
-
Jun 7th, 2010, 08:28 PM
#5
Re: Remove all non digit characters
PHP Code:
if(preg_match('/^\d+$/', $str)){ echo "matched!\n"; }else{ echo "no match.\n"; }
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|