Filtering numbers in PHP

0

I have the following phone number in the database: (45) 9 9874-4700

Is there any function that I just leave NUMBERS? what character is in the middle of the tag?

    
asked by anonymous 24.02.2018 / 20:08

1 answer

3

Yes. You can use the preg_replace function. It will use regular expressions to remove, change certain characters.

Example:

preg_replace("/\D/", "", "(45) 9 9874-4700");

In regular expressions, \D means: All characters other than 0 to 9.

That is, we select all the characters that are not numbers and in the second parameters we inform by which characters we must change (in this case by none).

link

    
24.02.2018 / 20:10