欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

php 实现页面跳转的四种方式

程序员文章站 2022-05-15 22:45:34
...
<?php

        header("refresh:2;url=http://www.baidu.com");
        header("location:http://www.baidu.com");
        echo "<meta charset='UTF-8' http-equiv='refresh' content='2;url=https://www.ipa361.com'>";
         echo "<script>window.location.href='http://www.taobao.com'</script>";

或者还有一种,form表单自动提交跳转

<html>
<head>
    <meta charset="utf-8">
</head>
<body onload="load()">
<form id="formCommit" action="http://www.baidu.com" method="post">
<input type="hidden" id = "req" name="req" value="<?php echo htmlspecialchars($param['resp']);?>" />
<input type="hidden" id = "sign" name="sign" value="<?php echo htmlspecialchars($param['sign']);?>" />
</form>
<script type="text/javascript">
function load(){
   document.getElementById("formCommit").submit();
}
</script>
</body>
</html>
php 大小写转换
//  BigTechnologyLiterature  转成 big_technology_literature
    public function get_table_name($model)
    {
//        字符串转数组,
        $arr=str_split($model,1);
        $str1=strtolower($arr[0]);

        for ($i=1;$i<count($arr);$i++){
            if(preg_match('/^[A-Z]+$/', $arr[$i]))
            {
                $str1.='_'.strtolower($arr[$i]);
            }else{
                $str1.=$arr[$i];
            }


        }

       return $str1;

    }

获取表字段的备注
<?php 

/**
 * 获取数据库字段注释
 *
 * @param string $table_name 数据表名称(必须,不含前缀)
 * @param string $field 字段名称(默认获取全部字段,单个字段请输入字段名称)
 * @param string $table_schema 数据库名称(可选)
 * @return string
 */
function get_db_column_comment($table_name = '', $field = true, $table_schema = ''){
    // 接收参数
    $database = config('database');
    $table_schema = empty($table_schema) ? $database['database'] : $table_schema;
    $table_name = $database['prefix'] . $table_name;
    
    // 缓存名称
    $fieldName = $field === true ? 'allField' : $field;
    $cacheKeyName = 'db_' . $table_schema . '_' . $table_name . '_' . $fieldName;
    
    // 处理参数
    $param = [
        $table_name,
        $table_schema
    ];
    
    // 字段
    $columeName = '';
    if($field !== true){
        $param[] = $field;
        $columeName = "AND COLUMN_NAME = ?";
    }
    
    // 查询结果
    $result = Db :: query("SELECT COLUMN_NAME as field,column_comment as comment FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = ? AND table_schema = ? $columeName", $param);
    // pp(Db :: getlastsql());
    if(empty($result) && $field !== true){
        return $table_name . '表' . $field . '字段不存在';
    }
    
    // 处理结果
    foreach($result as $k => $v){
        if(strpos($v['comment'], '#*#') !== false){
            $tmpArr = explode('#*#', $v['comment']);
            $data[$v['field']] = json_decode(end($tmpArr), true);
        }
    }
    
    // 字段注释格式不正确
    if(empty($data)){
        return $table_name . '表' . $field . '字段注释格式不正确';
    }
    
    return count($data) == 1 ? reset($data) : $data;
}
print_r(get_db_column_comment('user','tp5'));