This is for future developers, you can also try this. Simple too
echo preg_replace('/\D/', '', '604-619-5135');
a much more practical way for those who do not want to use regex:
$data = filter_var($data, FILTER_SANITIZE_NUMBER_INT);
note: it works with phone numbers too.
You would need to enclose the pattern in a delimiter - typically a slash (/) is used. Try this:
echo preg_replace("/[^0-9]/","",'604-619-5135');
Source: Stackoverflow.com