screen resolution with PHP - question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DonRamos
Forum Newbie
Posts: 3
Joined: Wed Sep 09, 2009 2:00 pm

screen resolution with PHP - question.

Post by DonRamos »

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
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: screen resolution with PHP - question.

Post by Mirge »

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
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.

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.
Post Reply