Huh, that's almost the one I supplied to your other question xD
Change the (.*?)
to ([0-9]+)
if (preg_match_all("/(?<=First)([0-9]+)(?=Second)/s", $haystack, $result))
for ($i = 1; count($result) > $i; $i++) {
print_r($result[$i]);
}
.*?
will match any character (except newlines) and to match only numbers in between your delimiters "First" and "Second", you will need to change it to [0-9]
. Then, I assume that there can't be nothing in between them, so we use a +
instead of a *
.
I'm not sure why you used [^0-9]
in the beginning. Usually [^0-9]
means one character which is not a number, and putting it there doesn't really do something useful, at least in my opinion.
Cleaning up a little, you could remove a few things that aren't needed to get the required output:
if (preg_match_all("/(?<=First)[0-9]+(?=Second)/", $haystack, $result))
print_r($result[0]);