例如,说:
<?php
// Grab the ID from URL, e.g. example.com/?p=123
$post_id = $_GET['p'];
?>
如何检查变量$post_id是否为数字和正整数(即 0-9,不是浮点数、分数或负数)?
编辑:不能使用is_int,因为$_GET返回一个字符串。认为我需要使用intval()or ctype_digit(),后者似乎更合适。例如:
if( ctype_digit( $post_id ) ) { ... }