Hello everyone,
I have a small script that takes the screen width with screen.width from java. it-s ok to post this value on the screen... but I need to make some operation with this variable. The problem is... I don't know what kind is it? is not integer, string...
<?php
$width = "<script>document.write(screen.width);</script>";
echo $width; // it shows ok my screen width everytime.... but i cannot do operation with $width...
if ($width >= 1280) echo 'OK!'; // it will not write the OK! message....
?>
I tried with (int)$width ... wich will be 0, also tried intval($width) wich also returns 0;
tried this small code... wich works ok with any other string but not in my case:
$new_string = ereg_replace("[^0-9]", "", $width);
echo $new_string;
I really don't know how to convert this variable so i can work with it....
Anyone, any ideea ?
Thanks.
DR
screen resolution with PHP - question.
Moderator: General Moderators
Re: screen resolution with PHP - question.
The value of $width is that actual text... the script tag, etc. What your browser is showing is NOT the actual value of $width in PHP's view... but the JS-parsed value of the text that $width contains. If you want to gain access to the screen resolution with PHP, you'll need to send the actual value to PHP.DonRamos wrote:Hello everyone,
I have a small script that takes the screen width with screen.width from java. it-s ok to post this value on the screen... but I need to make some operation with this variable. The problem is... I don't know what kind is it? is not integer, string...
<?php
$width = "<script>document.write(screen.width);</script>";
echo $width; // it shows ok my screen width everytime.... but i cannot do operation with $width...
if ($width >= 1280) echo 'OK!'; // it will not write the OK! message....
?>
I tried with (int)$width ... wich will be 0, also tried intval($width) wich also returns 0;
tried this small code... wich works ok with any other string but not in my case:
$new_string = ereg_replace("[^0-9]", "", $width);
echo $new_string;
I really don't know how to convert this variable so i can work with it....
Anyone, any ideea ?
Thanks.
DR
Utilizing AJAX is _one_ solution... if you needed the screen resolution for the current page. Or you could direct the visitor to a page where you pull the resolution according to JS, and forward to the next page which uses the dimensions, etc.