Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * 接收GET或者POST数据,GET优先,也可以通过get.name或者post.name接收
- * @param string $name 要取的name值
- * @param bool [$isInt=false] 接收的数据类型是否为整型
- * @param mixed [$default=''] 没有接收到值的时候返回的默认值
- * @return mixed name值不存在返回false,否则返回其值
- */
- function I($name,$isInt=false,$default=''){
- //尝试接收get
- $value = isset($_GET[$name])?$_GET[$name]:false;
- if($value===false){
- //没有get,尝试接收post
- $value = isset($_POST[$name])?$_POST[$name]:false;
- if($value===false){
- //没有get,post,尝试接收对象方式
- if(strcasecmp(substr($name,0,4),'get.')===0){
- //对象方式get
- $name = substr($name,4);
- $value = isset($_GET[$name])?$_GET[$name]:false;
- }elseif(strcasecmp(substr($name,0,5),'post.')===0){
- //对象方式get
- $name = substr($name,5);
- $value = isset($_POST[$name])?$_POST[$name]:false;
- }else{
- return $default;
- }
- }
- }
- if($isInt){
- return intval($value);
- }else{
- return addslashes($value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement