这可能看起来微不足道,但是intval()
在以下情况下返回0:
$window_width = "<script type='text/javascript'>document.write(window.innerWidth);</script>";
$window_width2 = intval($window_width);
echo $window_width2;
$window_width
将变成"1366"
。
$window_width2
将会是0
。
我需要$window_width2
是integer
,而不是string
。
$window_width
持有不能转换为string
的string
(不是window.innerWidth
),因此 0
返回!
PHP
在sever
上执行(在JavaScript
执行之前),所以不可能通过PHP
访问window.innerWidth
,使用AJAX
通过PHP
发送数据。
var成功时的整数值,失败时为0。
字符串很可能返回0,尽管这取决于字符串最左边的字符。
$window_width
不能是1366,因为你正在混合PHP和Javascript。
PHP在服务器端执行,而JS在用户端执行。这意味着你不能在PHP中直接使用JS中的值。