0
I have the following phone in the database: (45) 9 9874-4700
Is there any function that I leave only NUMBERS? regardless of which character is in the middle of the tag?
0
I have the following phone in the database: (45) 9 9874-4700
Is there any function that I leave only NUMBERS? regardless of which character is in the middle of the tag?
3
Yes. You can use the function preg_replace
. It will use regular expressions to remove, change certain characters.
Example:
preg_replace("/\D/", "", "(45) 9 9874-4700");
In regular expressions, the \D
means: All characters different from 0 to 9.
That is, we select all characters that are not numbers and in the second parameter we inform which characters to exchange (in this case for none).
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
Exactly, thank you!
– Sr. André Baill