<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/3/25
* Time: 11:03
*/
$data = [
[
"text" =>"姓 名:",
"tag" =>"input",
"attr" =>['type'=>'text','name'=>'username']
],
[
"text" =>"密 名:",
"tag" =>"input",
"attr" =>['type'=>'password','name'=>'pwd']
],
[
"text" =>"邮 箱:",
"tag" =>"input",
"attr" =>['type'=>'text','name'=>'email']
],
[
"text" =>"电 话:",
"tag" =>"input",
"attr" =>['type'=>'text','name'=>'tel']
],
[
'tag' => 'input',
'text' => '性 别:',
'attr' => ['type' => 'radio', 'name' => 'gender'],
'option' => ['m' => '男', 'w' => '女']
],
[
'tag' => 'select',
'text' => '住 址:',
'attr' => ['name' => 'area'],
'option' => ['' => '--请选择--', 'BJ' => '北京', 'SH' => '上海', 'SZ' => '深圳',]
],
[
'tag' => 'textarea',
'text' => '自我介绍:',
'attr' => ['name' => 'declare', 'cols' => '50', 'rows' => '5']
]
];
<?php
include "data.php";
function generate(){
$html ="";
global $data;
foreach ($data as $value){
if ($value["tag"]=="input"){
// 调用Input生成文本框
$html=$html.input_html($value);
}
else if ($value["tag"]=="select"){
//调用select生成下拉列表
$html=$html.select_html($value);
}
else if ($value["tag"]=="textarea"){
//调用生成文本域
}
}echo "";
return $html;
}
//列表框
function input_html($value){
$html="";
if ($value["attr"]["type"]=='text'){
$html=$value["text"]."";
}
else if ($value["attr"]["type"]=='radio'){
$html=$html."