In the code example below I am getting the width of a device screen via a javascript call. Using the Responsive Design Mode
in FireFox
, I set the screen width to 600, and refresh the browser. The values I list in the code below are from running the code with the screen at 600. PHP
sees the 600 value, but doesn’t compare it correctly with an actual number.
//php
$currentWidth = "<script>document.write( $(window).innerWidth() )</script>";
print "<h1>Screen Width: $currentWidth</h1>"; // output: Screen Width 600
if( $currentWidth >= 990 ){
print "<h1>Large Screen: $currentWidth</h1>";
}else{
print "<h1>Small Screen: $currentWidth</h1>";
}
// output: Large Screen: 600
- The
if( $currentWidth >= 990 ){
is failing. It should fall through to theelse
block.
I thought maybe the 600
was not seen as an int, so I printed out the variable type and it shows as String
. I tried a couple of casts
like (int) $currentWidth
and intval
, they show/make the value as 0 (zero).
I added a * before and after $currentWidth
in the printout to see if anything was there but just not showing.
Not sure what I’m missing. Hoping brighter minds than mine will see what is going on.
Thanks