Get the date and time from a string with a specific prefix

there is a page code it has a line You have access until: 2011-11-27 18:28:45
I need to get the date and time. using preg_match


Answer 1, authority 100%

Well, what are the difficulties?

take the given line,

You have access until: 2011-11-27 18:28:45

You have access until: – this part of the string will most likely not change, so the usual one will most likely suffice

echo substr("You have access until: 2011-11-27 18:28:45", strlen("You have access until: "));

but if you really want to apply preg_match – then:

We need to make a mask for the date and time in the given format.

So:
\d – digit
{x} – the number of characters that match the mask given by the previous characters. For example: \d{4} – this mask specifies any 4 numbers.

total we get something like:

if (preg_match("~You have access until: (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})~", "You have access until: 2011-11-27 18:28:45", $m)) {
    print_r($m);
}

But actually \d+ would be enough for us in this case.