Just replace the variable value $largura
in the expression
$largura = (int)$largura;
to see what you want to convert into INT.
Making the replacement we have:
$largura = (int)<script type =text/javascript> var largura = screen.width; document.write(largura); </script>;
Can’t convert an entire javascript.
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 has no numerical value will be converted to 0(zero)
Regarding echo $largura;
, replacing the variable value $largura
we have:
echo "<script type =text/javascript> var largura = screen.width; document.write(largura); </script>"
that prints on the page a javascript that in turn prints the variable value largura
with document.write
.
See how it works here. (does not allow javascript, so it will not run Document.write)
If you want to see the javascript working copy the code below and paste on this page http://phptester.net/
$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';
Actually when you do
$largura = '<script type="text/javascript"> var largura = screen.width; document.write(largura); </script>';
you are not passing the value"1366"
for your variable$largura
. You’re assigning all this string for your variable, so the casting(int)
returns0
.– user98628
When you give the
echo
the code prints out1366
, because the script in the document. Who is printing1366
is the JS:document.write(largura);
.– user98628
Just replace the variable value
$largura
in the expression$largura = (int)$largura;
to see what you want to convert into INT. Making the replacement we have:$largura = (int)<script type =text/javascript> var largura = screen.width; document.write(largura); </script>;
Can’t convert an entire javascript.– user60252