php, string to int
how convert from string to int?
If i print $width_s, get: 1024
If i print $width, get 0.
How convert string to integer(number) ?
$width_s = '<script language="javascript">document.write(scr开发者_如何学编程een.width)</script>';
$width = (int)$width_s;
var_dump($width);
PHP is executed on the server side, while javascript is executed on the client side; if you want a value from javascript to be sent to PHP, you will need to write up some kind of script to pass the data, via AJAX, GET, etc.
edit: database != data
You can use the php function intval($string). Learn about it here.
see:
http://www.php.net/intval
The problem with your code is that its a string with characters that aren't numbers, so casting to int isn't possible. Intval returns only the numeric part of a given string.
精彩评论