php method to remove non-digits: first create a PHP sample file; then create a string containing non-digits; finally pass "preg_replace('/\D/','','a1asd2asd3a'); " method can remove non-digits.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
Specific questions:
Looking for a php regular expression to remove non-digits
For example:
"a1asd2asd3a"
Output after regular filtering
123
Don’t use intval() or (int) because it won’t work if it’s more than 10 digits
Solution
echo preg_replace('/\D/','','a1asd2asd3a');
[Recommended Study: PHP video tutorial】
The above is the detailed content of How to remove non-digits in php. For more information, please follow other related articles on the PHP Chinese website!