我尝试使用javascript在php中获取屏幕宽度,它以字符串类型返回。 我不能使用if语句为屏幕选择了最佳广告尺寸
$screenwidth = '<script>
document.write(window.innerWidth)
</script>';
$nu = (int)$screenwidth;
echo $nu;
任何帮助
答案 0 :(得分:0)
您的代码无法在php中获得窗口大小
<html>
<head></head>
<body>
<script>docuemnt.write(window.innerWidth);</script>
</body>
</html>
,当您在页面中回显$ screenWidth然后打印该窗口大小时,它就起作用了。
所以在php中这只是一个字符串。