如何将一个字符串分成两个,然后将其中一个字符串变成一个数字[php]

I have this string:

"$string="Med0x2"

What I want, is to separate it into two strings, like this:

$string1="Med0x" ; $string2="2";

And then convert $string2 into an int variable (covert from string to int)

How do I do this?

$string = "Med0x2";
$string1 = substr($string, 0, 5);
$string2 = substr($string, 5);
$integer = (int) $string2;

you need to Find sub string in first va

$string1 = "Med0x2";
$string2 = (int) substr($string1, -1);
echo "$string2";
echo is_int($string2) ? "yes":"no";

You can use preg_match for this, using capturing groups to get the parts of the string.
Something like this -

$string = "Med0x2";
$regex = "/^(.*?x)(\d+)$/";
if(preg_match($regex, $string, $matches)){
  $string1 = $matches[1];
  $string2 = $matches[2];
  $integer = intval($string2);
}