Home  >  Article  >  Backend Development  >  How to remove non-digits in php

How to remove non-digits in php

藏色散人
藏色散人Original
2021-03-30 09:31:321719browse

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.

How to remove non-digits in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn