thinkphp 判断一个字符串是纯数字?
<eqname=”name”value=”value”>value</eq>name的值有123,abc,234,sdc...
<eq name=”name” value=”value”>value</eq> name的值有123,abc,234,sdc
展开
1个回答
展开全部
用is_numeric判断
php官方的例子
<?php
$d = @$_GET['d'];
/*
assuming that passing value of d in the mysql
$sql = "select * from books where bookid = '$d' "
*/
/*
now check if $d is numeric?
*/
if(!is_numeric($d)){
$d = preg_replace("/[^0-9]+/", "", $d);
}
echo "Cleared value: $d \n<br />Original Vlaue:".@$_GET['d'];
//then using clear value of $d in the mysql query
$sql = "select * from books where bookid = '$d' ";
?>
php官方的例子
<?php
$d = @$_GET['d'];
/*
assuming that passing value of d in the mysql
$sql = "select * from books where bookid = '$d' "
*/
/*
now check if $d is numeric?
*/
if(!is_numeric($d)){
$d = preg_replace("/[^0-9]+/", "", $d);
}
echo "Cleared value: $d \n<br />Original Vlaue:".@$_GET['d'];
//then using clear value of $d in the mysql query
$sql = "select * from books where bookid = '$d' ";
?>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询