I have a string like this : x320h220
I want to split this string into two variables : $width and $height
I Can split it using explode but I have to use this method twice to get these values so I found out preg_split will do the trick. But I don't know the Regex to split these string into two variables (find if string contain x then cut the rest till h and then cut the rest again in another variable) which they should be like :
$width = 320;
$height = 220;
any suggestion ?
Use
preg_match(), notpreg_split(). Use capture groups to extract the two numbers.In the regexp:
xandhmatch themselves literally\d+matches a sequence of digits()around the digit sequence creates a capture group, so the matched portions are put into the$matcharray.