There's a lot of good answers here. Some of the answers related to strpos, strlen, and using delimiters are wrong.
Here is working code that I used to find the height and width of an image using delimiters, strpos, strlen, and substr.
$imageURL = https://images.pexels.com/photos/5726359/pexels-photo-5726359.jpeg?auto=compress&cs=tinysrgb&h=650&w=940;
// Get Height
$firstDelimiter = "&h=";
$secondDelimiter = "&w=";
$strPosStart = strpos($imageURL, $firstDelimiter)+3;
$strPosEnd = strpos($imageURL, $secondDelimiter)-$strPosStart;
$height = substr($imageURL, $strPosStart, $strPosEnd);
echo '<br>'.$height;
// Get Width
$firstDelimiter = "&w=";
$strPosStart = strpos($imageURL, $firstDelimiter)+3;
$strPosEnd = strlen($imageURL);
$width = substr($imageURL, $strPosStart, $strPosEnd);
echo '<br>'.$width;
Basically, define your string delimiters. You can also set them programmatically if you wish.
Then figure out where each delimiter starts and ends. You don't need to use multiple characters like I did, but make sure you have enough characters so it doesn't capture something else in the string.
It then figures out the starting and ending position of where the delimiter is found.
Substr requires the string it will be processing, the starting point, and the LENGTH of the string to capture. This is why there is subtraction done when calculating the height.
The width example uses string length instead since I know it will always be at the end of the string.