Tp5自动验证

class DB

{
private $address = 'mysql.21future.com';

private $username = 'manbang';

private $password = 'M8356b8356';

private $db = 'manbang';

private $table = 'fa_contacts';

private $con;

 

public function __construct()

{

$con = mysqli_connect($this->address,$this->username,$this->password,$this->db,'3306');

if (mysqli_connect_errno())

{

die('Could not connect: ' . mysql_error());

}else{

$con->set_charset('utf8');

$this->con=$con;

}

}

 

 

public function index(){

//2 创建sql

$_sql = "show full columns from ".$this->table;

$_result = $this->con->query($_sql);

 

while ($access= $_result->fetch_assoc()){

// echo "

";

// dump($access);

$data[]=self::HandleArr($access);

}

$data=array_filter($data);

// return view('index',['data'=>$data]);

return $data;

}

 

public function data(){

$html=" $arr=$_POST;
$res = array_map(function($val) {

return array_filter($val);

}, $arr);
$res=array_filter($res);
$rule="\n\t\t";

$message="\n\t\t";

foreach ($res as $key => $value) {

$rule .="'${key}' => '";

foreach ($value as $k => $v) {

//添加条件理由

if(strpos($k, '_'.md5(1))){

if(strpos($v,'@@')){

$valmsg=explode('@@', $v);

$v=$valmsg[0];

$msg=$valmsg[1];

}else{

$msg=$k.'的提示信息';

}

$rule .=str_replace('_'.md5(1),'', $k).":${v}|";

$message .="'${key}.".str_replace('_'.md5(1),'', $k)."' => '${msg}',\n\t\t";

}elseif(strpos($k, '_'.md5(2))){

$rule .=str_replace('_'.md5(2),'', $k).":${v}|";

}else{

$rule .="${k}|";

$message .="'${key}.${k}' => '$v',\n\t\t";

}

 

}

$rule=trim($rule,'|')."',\n\t\t";

 

}

$txt = sprintf($html,$rule,$message);

// print($rule);
// print($message);
if(file_put_contents('cheng.php', $txt,FILE_APPEND)){
echo 'success';
}else{
echo 'error';
}

die;

 

}

 

static public function HandleArr($arr)

{

if($arr['Field']=='id')

return [];

$preg='/^([a-z]+)\((\d+)(,?\d+)?\)/';

preg_match($preg,$arr['Type'],$e);

@$len=['type'=>$e[1],'leng'=>$e[2]];

 

if($arr['Key']=='PRI'){

$arr['Null']='YES';

}

 

$must=$arr['Null']=='YES'?0:1;

return ['field'=>$arr['Field'],'leng'=>$len,'must'=>$must,'comment'=>$arr['Comment']];

}

}

if(isset($_GET['type'])){

$obj = new DB();

$data=$obj->data();

}else{

$obj = new DB();

$data=$obj->index();

}

?>

Document

TP5自动验证

foreach ($data as $key => $vo) {

# code...

?>

必选: value="不可为空">

可选: value="">

}

?>

 

转载于:https://www.cnblogs.com/chengfengchi/p/9907685.html

你可能感兴趣的:(Tp5自动验证)