I have a $custom_size
variable in PHP that I need to extract a Width
and Height
number from.
The format of the string can contain different values so it is not ALWAYS in the proper format. Meaning sometimes it may have characters that do not belong.
The one thing that will always be the same though is the Width
value will always be the number on the LEFT of the x and the Height
value will always be the number on the RIGHT side of the x
Some sample strings may be in this format below...
$custom_size = '48"x40"'
$custom_size = '48x40'
$custom_size = '48"Wx40"H'
$custom_size = '48Wx40H'
$custom_size = '48 x 40'
I need help extracting the number on the left and assigning it to a $width
variable and the number on the right to a $height
variable.
In addition to the example strings, I imagine there could be more possibilities of similar strings as well but always similar.
I would appreciate any help in how to do this, I am not that great with Regular Expressions
and I think that might be required due to all the possible combinations?
Basically need to figure out the best way to assign all numbers to the LEFT of an x
or X
to a $width variable
and all numbers to the RIGHT of it to a $height variable