在PHP中将字符串转换为int

sof*_*nic 1 javascript php

以下是我的代码片段,我将屏幕宽度分配给变量$width.但是当我将它转换为整数并回显它时,0会返回.

$width = '<script> document.write(window.screen.width); </script>';
//if i echo $width it shows 1366 which is width of my screen
$height = '<script> document.write(window.screen.height); </script>';
echo "The height is = $height"."<br>The width is = ".$width;
$a = (int)($width);
echo $a;
Run Code Online (Sandbox Code Playgroud)

我要求指导这种转换完美.

Dan*_*ite 5

实际上你当时没有获得屏幕尺寸.这在客户端运行.您必须对服务器进行ajax调用才能进行设置.

  • @softgenic没有.PHP是**服务器端**. (2认同)