I'm hoping someone can help me. I would like a PHP function that takes a string (X), and searches it for another string (Y). After Y is found (left to right search), the function will return only numbers found after Y but will not return numbers (or anything after the search finds another non-numeric character in the string Y (to the right).
Example: Searching for "peas, "
String = 'Tomorrow we will eat peas, 10 times as many as we did on the 7th or 8th of this month.'
Returns 10
Can someone help me out please?
$string = 'Tomorrow we will eat peas, 10 times as many as we did on the 7th or 8th of this month.';
$search = 'peas, ';
// Turn the search string into a regular expression
$regexp = '/' . preg_quote($search) . '(\d+)/';
preg_match($regexp, $string, $match);
$number = $match[1];