Just replace the value of the $largura
variable in the
$largura = (int)$largura;
to see what you want to convert to INT.
Replacing it we have:
$largura = (int)<script type =text/javascript> var largura = screen.width; document.write(largura); </script>;
You can not convert a javascript to INTEGER.
In fact, the conversion from string to integer depends on the format of the string, so PHP evaluates the format of the string and if it does not have any numerical value it will be converted to 0
For echo $largura;
, replacing the value of the variable $largura
we have:
echo "<script type =text/javascript> var largura = screen.width; document.write(largura); </script>"
which prints on the page a javascript that in turn prints the value of the variable largura
with document.write
.
See how here . (does not allow javascript, so it will not execute the document.write)
If you would like to see javascript working, please copy and paste the following code: link
$largura = "<script type =text/javascript> var largura = screen.width; document.write(largura); </script>";
echo "<br>";
echo gettype($largura). " AQUI ELE IMPRIME string";
echo "<br><br>";
echo "proxima linha é o javaScript veja no código fonte do frame direito";
echo "<br><br>";
echo $largura. " AQUI o JAVASCRIPT IMPRIME a largura";
echo "<br><br>querendo passar para INT um código javascript<br><br>";
$largura = (int)$largura;
echo $largura;
echo "<br><br>";
echo gettype($largura). ' AQUI ELE IMPRIME integer porque agora $largura = 0';
echo "<br><br>";
echo $largura. ' AQUI ELE IMPRIME 0 porque $largura é 0';