Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /**
  5. * 接收GET或者POST数据,GET优先,也可以通过get.name或者post.name接收
  6. * @param string $name 要取的name值
  7. * @param bool [$isInt=false] 接收的数据类型是否为整型
  8. * @param mixed [$default=''] 没有接收到值的时候返回的默认值
  9. * @return mixed name值不存在返回false,否则返回其值
  10. */
  11.  
  12. function I($name,$isInt=false,$default=''){
  13. //尝试接收get
  14. $value = isset($_GET[$name])?$_GET[$name]:false;
  15. if($value===false){
  16. //没有get,尝试接收post
  17. $value = isset($_POST[$name])?$_POST[$name]:false;
  18. if($value===false){
  19. //没有get,post,尝试接收对象方式
  20. if(strcasecmp(substr($name,0,4),'get.')===0){
  21. //对象方式get
  22. $name = substr($name,4);
  23. $value = isset($_GET[$name])?$_GET[$name]:false;
  24. }elseif(strcasecmp(substr($name,0,5),'post.')===0){
  25. //对象方式get
  26. $name = substr($name,5);
  27. $value = isset($_POST[$name])?$_POST[$name]:false;
  28. }else{
  29. return $default;
  30. }
  31. }
  32. }
  33. if($isInt){
  34. return intval($value);
  35. }else{
  36. return addslashes($value);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement