How can I take a string and remove all non digit characters from the string? Unfortunately my regex skills arent so hot :(
Printable View
How can I take a string and remove all non digit characters from the string? Unfortunately my regex skills arent so hot :(
This seems to be working well:
Any objections?Code:$str = "1234567890abc!@#$%^&*()-=_+[]{}|\\'\"?/><,.";
echo preg_replace("%[^0-9]%", "", $str);
No objections. You can use \d as well as 0-9.
how do i turn this into a preg_match?
I need to match if a string is all digits, if so true else false
PHP Code:if(preg_match('/^\d+$/', $str)){
echo "matched!\n";
}else{
echo "no match.\n";
}