I’m new to php and I need a hand.
I have width by height dimensions which are output to a single string (width x height). I need to separate the width and the height. The dimensions will always be less than 100, but could include decimal values. There’s also the possibility of whitespace before or after the dimensions.
Here are a few example dimensions:
8×10, 10×12, 24.5×36.625
I think I could accomplish the task using strpos and substr, but would a regular expression be faster? more elegant? more accurate?
[side question: what’s a good way to learn regex? are there any books/websites you’d recommend?]
$string=' 8.5x10';
$string=trim($string);
$x = stripos($string,'x');
$size1 = substr($string, 0, $x);
$size2 = substr($string, $x+1);
echo $size1 . '<br />';
echo $size2;
1 Answer