PHP - Extract numbers from string

https://stackoverflow.com/questions/6278296/extract-numbers-from-a-string

String example: ~8500~TOTALTOPAY
Using regex

preg_match('/\d+/', '~8500~TOTALTOPAY', $matches);
$number = $matches[0];

Or, if you don't want to use regex

$number = intVal(filter_var('~8500~TOTALTOPAY', FILTER_SANITIZE_NUMBER_INT));