Page 1 of 1
Get value before and/or after "x" in a string?
Posted: Fri Aug 06, 2010 10:28 am
by dominod
Hi,
I am working with screen resolutions and so far I managed to get the users screen resolution into a cookie which states "1440x900" (My resolution).
I just wonder how I can get width and height in two different strings? Something that removes "x" and everything after it to get width and vice verca for height..

Re: Get value before and/or after "x" in a string?
Posted: Fri Aug 06, 2010 2:20 pm
by Christopher
Code: Select all
list($width, $height) = explode('x', $resolution);
Re: Get value before and/or after "x" in a string?
Posted: Fri Aug 06, 2010 6:26 pm
by dominod
That was easy! lol
Thanks alot!
Have a nice one!
Re: Get value before and/or after "x" in a string?
Posted: Fri Aug 06, 2010 10:17 pm
by s.dot
You should use the example above.
I was just bored and did it a different way.
Code: Select all
$str = '1440x900';
$pos = strpos($str, 'x');
$width = substr($str, 0, $pos);
$height = substr($str, $pos+1);
Re: Get value before and/or after "x" in a string?
Posted: Sat Aug 07, 2010 12:37 am
by BDKR
s.dot wrote:
You should use the example above.
I was just bored and did it a different way.
Code: Select all
$str = '1440x900';
$pos = strpos($str, 'x');
$width = substr($str, 0, $pos);
$height = substr($str, $pos+1);
You are right that he should use the example posted above, but it's good you posted this example as not all strings are formatted so clearly or nicely as to facilitate the use of explode.