PHP intval() returns 0


PHP intval() returns 0

这可能看起来微不足道,但是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_width2integer,而不是string

$window_width持有不能转换为stringstring(不是window.innerWidth),因此 0 返回!

PHPsever上执行(在JavaScript执行之前),所以不可能通过PHP访问window.innerWidth,使用AJAX通过PHP发送数据。

var成功时的整数值,失败时为0。

字符串很可能返回0,尽管这取决于字符串最左边的字符。

$window_width不能是1366,因为你正在混合PHP和Javascript。

PHP在服务器端执行,而JS在用户端执行。这意味着你不能在PHP中直接使用JS中的值。