Reputation: 9
I have tried everything but answer is probably much simple. Variable $data['phone']
is for example 954a23589
and I want only numbers so ill get them.
$phoneW = strval($data['phone']);
preg_match_all('!\d+!', $phoneW, $matches);
print_r(array_values($matches)); echo '<br /><br />';
The output is
Array ( [0] => Array ( [0] => 954 [1] => 23589 ) )
I want everyone of them together as string or int (does not matter).
Upvotes: 0
Views: 70
Reputation: 96325
and I want only numbers so ill get them
Why not replace everything that is not a digit with “nothing”?
echo preg_replace('#[^\d]#', '', '954a23589');
Upvotes: 0
Reputation: 265261
It's probably easier to replace every non-digit with an empty string:
$number = preg_replace('/\D+/', '', $phoneW);
Upvotes: 7