Check if string ends with number and get the number if true

Viewed 661

How can i check if a string ends with a number and if true, push the number to an array (for example)? I know how to check if a string ends with a number, I solved it like this:

$mystring = "t123";

$ret = preg_match("/t[0-9+]/", $mystring);
if ($ret == true)
{
    echo "preg_match <br>";
    //Now get the number
}
else
{
    echo "no match <br>";
}

Let's assume all strings start with the letter t and are composited with a number e.g. t1,t224, t353253 ...

But how can I cut this number out if there is one? In my code example there is 123 at the end of the string, how can I cut it out and for example push it to an array with array_push?

4 Answers
Related