In this tutorial we will learn that how to find numbers from string in PHP.
Here we will use
preg_match_all() function to get numbers from string in PHP.
The preg_match_all() function returns the number of matches according to the pattern which we created.
preg_match_all(pattern, input, matches, flags, offset)
Now follow below code to get numbers from string in PHP.
$string = 'You have 500 rupees and 13 paise remaining in your card ending with 3785';
preg_match_all('!\d+!', $string, $matches);