Convert strings to integers (int), intval(), and printf() in PHP.
Related recommendations: "PHP Tutorial"
int
<?php $foo = "1"; // $foo 是字符串类型 $bar = (int)$foo; // $bar 是整型 ?>
intval
<?php $foo = "1"; // $foo 是字符串类型 $bar = intval($foo); // $bar 是整型 ?>
sprintf
<?php $foo = "1"; // $foo 是字符串类型 $bar = sprintf("%d", $foo); // $bar 是字符串类型 ?>
The above is the detailed content of How to convert php string to integer. For more information, please follow other related articles on the PHP Chinese website!