zoukankan      html  css  js  c++  java
  • php封装参数检查

    2021年5月1日09:30:23

    if (!function_exists('parameterCheck')) {
    
        /**
         * 如果是double的话,也使用float,需要处理其他类型数据自己添加
         * @param type $param 需要处理的参数
         * @param type $ExpectDataType  期望返回数据类型
         * @param type $defaultValue  如果没有值返回的默认值
         * @return type
         * @throws Exception
         */
        function parameterCheck($param, $ExpectDataType, $defaultValue) {
            $dataType = ['int', 'float', 'string', 'array'];
            if (!in_array($ExpectDataType, $dataType)) {
                throw new Exception('数据类型不存在');
            }
            if (empty($param)) {
                return $defaultValue;
            }
            if ($ExpectDataType == 'int') {
                return (int) htmlFilter($param);
            } elseif ($ExpectDataType == 'float') {
                return (float) htmlFilter($param);
            } elseif ($ExpectDataType == 'string') {
                return (string) htmlFilter($param);
            } elseif ($ExpectDataType == 'array') {
                return (array) $param;
            }
        }
    
    }
    
    if (!function_exists('htmlFilter')) {
    
        /**
         * 
         * @param type $param 需要html转义和去除空格的参数
         * @throws Exception
         */
        function htmlFilter($param) {
            return htmlspecialchars(trim($param), ENT_QUOTES, "UTF-8");
        }
    
    }
    QQ群 247823727 博客文件如果不能下载请进群下载
    如果公司项目有技术瓶颈问题,如有需要,请联系我,提供技术服务 QQ: 903464207
  • 相关阅读:
    Dropplets – 极简的 Markdown 博客平台
    T3
    Awesomplete
    SVG Drawing Animation
    Dom Animator – 提供 Dom 注释动画的 JS 库
    Electron
    很赞的效果!互动的页面元素拖放着色实验
    BookBlock
    雷军投资的理财网站,年化收益13%!
    Rainyday.js – 使用 JavaScript 实现雨滴效果
  • 原文地址:https://www.cnblogs.com/zx-admin/p/14723832.html
Copyright © 2011-2022 走看看