Are there any special conditions about grabbing the number?
To grab the first number, just use /\d+/
with preg_match
.
if (preg_match('/\d+/', $subject, $match)) {
$job_id = (int) $match[0];
}
Otherwise you could do something like the following which searches for a number preceeded by "job" (case-insensitive).
if (preg_match('/job (\d+)/i', $subject, $match)) {
$job_id = (int) $match[1];
}
(There are better alternatves for this regex, but best to keep things simple at first.)
Another option would be to move away from regular expressions into more basic parsing of a string:
sscanf($subject, 'Your Job %d ("%[^"]")', $job_id, $job_title);
// use $job_id and $job_title however you like
Of course, similar could be done with preg_match
but it's good to offer alternatives.