I have been researching this for a half hour and still can't figure it out. I am sure it is simple.
I want to match an id but only if it has "ID: " in front.
<?php
$string1 = "Payment: 1474";
$string2 = "Payment ID: 1474";
preg_match('/ID: ([0-9]){1,7}$/', $string1, $matches);
//array(0){} Good! This is the expected result.
preg_match('/ID: ([0-9]){1,7}$/', $string2, $matches);
//array(2) { [0]=> string(8) "ID: 1474" [1]=> string(1) "4" }
//I am glad it finds a match, but I want matches[0] to be only the id, 1474
?>
In other words, I need to find a match but I also need to specify what goes into the array.
Since I am having trouble learning this, I would appreciate if you don't just answer with code but also explain what it does. Thanks!