当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP 类型转换函数intval

PHP
用PHP与XML联手进行网站编程代码实例
使用PHP批量生成随机用户名
功能齐全的PHP发送邮件类代码附详细说明
php 防止单引号,双引号在接受页面转义
php表单提交程序的安全使用方法
兼容PHP5的PHP目录管理函数库
php下实现一个阿拉伯数字转中文数字的函数
php header()函数使用说明
PHP入门学习的几个不错的实例代码
php下intval()和(int)转换使用与区别
PHP令牌 Token改进版
Discuz 模板引擎的封装类代码
PHP批量生成缩略图的代码
php正则校验用户名介绍
php minixml详解
高级php注入方法集锦
php socket方式提交的post详解
用php过滤危险html代码的函数
php array_merge下进行数组合并的代码
PHP版自动生成文章摘要

PHP 类型转换函数intval


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 100 ::
收藏到网摘: n/a

不管什么类型 如果是数字,就返回数字,如果不是数字就返回0 在PHP中用$_GET['id']的时候就可以这样来一个转换...太好了 PHP代码
$id = intval($_GET['id']);
intval
(PHP 4, PHP 5)
intval — Get the integer value of a variable
Description
int intval ( mixed $var [, int $base= 10 ] )
Returns the integer value of var , using the specified base for the conversion (the default is base 10).
Parameters
var
The scalar value being converted to an integer
base
The base for the conversion (default is base 10)
Return Values
The integer value of var on success, or 0 on failure. Empty arrays and objects return 0, non-empty arrays and objects return 1.
The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807.
Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply.
Examples
复制代码 代码如下:

<?php
echo intval(42); // 42
echo intval(4.2); // 4
echo intval('42'); // 42
echo intval('+42'); // 42
echo intval('-42'); // -42
echo intval(042); // 34
echo intval('042'); // 42
echo intval(1e10); // 1410065408
echo intval('1e10'); // 1
echo intval(0x1A); // 26
echo intval(42000000); // 42000000
echo intval(420000000000000000000); // 0
echo intval('420000000000000000000'); // 2147483647
echo intval(42, 8); // 42
echo intval('42', 8); // 34
?>