How to remove non-digits in php

藏色散人
Release: 2023-03-09 08:02:01
Original
1735 people have browsed it

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');
Copy after login

[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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template