This might seem trivial, but the intval()
is returning 0 in the following case:
$window_width = "<script type='text/javascript'>document.write(window.innerWidth);</script>";
$window_width2 = intval($window_width);
echo $window_width2;
$window_width
will be "1366"
.
$window_width2
will be 0
.
I need $window_width2
to be integer
, not string
.
$window_width
is holding a string
(not window.innerWidth
) which can not be converted to string
hence 0
is returned!
PHP
is executed on sever
(Way Before JavaScript
is executed) so it is impossible to access window.innerWidth
over PHP
, use AJAX
to emit that data over PHP
.
Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply.
$window_width
can not be 1366, because you are mixing PHP and Javascript.
PHP is executed on Server side while JS is on User side. This means you can not just use values from JS in PHP.