1.打开JetBrains PhpStorm 2017.2.4 x64,
没有可以下载一个。
2.打开PHPstyle。
3.创建一个文件里面新建三个PHP。flie
分别为data,function,index。
4.data.php里面放二维数组。`
$data = [
[
“text” =>“姓 名:”,
“tag” =>“input”,
“attr” =>[‘type’=>‘text’,‘name’=>‘username’]
],
[
“text” =>“密 名:”,
“tag” =>“input”,
“attr” =>[‘type’=>‘text’,‘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’ => [‘as’ => ‘–请选择–’, ‘BJ’ => ‘北京’, ‘SH’ => ‘上海’, ‘SZ’ => ‘深圳’,]
],
[
‘tag’ => ‘textarea’,
‘text’ => ‘自我介绍:’,
‘attr’ => [‘name’ => ‘declare’, ‘cols’ => ‘50’, ‘rows’ => ‘5’]
]
];代码。 4.1——function.php里面放代码
<?php
/**
- Created by PhpStorm.
- User: lenovo
- Date: 19/3/27 027
- Time: 下午 3:03
*/
nclude “data.php”;
function arr(){
global $data;
h t m l = " " ; f o r e a c h ( html=""; foreach( html="";foreach(data as KaTeX parse error: Expected '}', got 'EOF' at end of input: …{ if (itme[“tag”]“input”){
// 调用生成 input的函数
h t m l = html= html=html.input_html(KaTeX parse error: Expected 'EOF', got '}' at position 17: …tme); }̲ elsei…itme[“tag”]“select”){
// 调用生成 select
h t m l . = s e l e c t h t m l ( html.=select_html( html.=selecthtml(itme);
}
elseif($itme[“tag”]==“textarea”){
// 调用生成 textarea
h t m l . = t e x t a r e a h t m l ( html.=textarea_html( html.=textareahtml(itme);
}
}
return $html;
};
function input_html($itme){
$html="";
// 判断是否文本框
if ($itme["attr"]["type"]=="text"){
// 生成文本框
$html=$itme["text"]."<input type='{$itme['attr']['type']}' name='{$itme['attr']['name']}'>";
}
// 判断是否单选按钮
elseif($itme["attr"]["type"]=="radio"){
$html=$itme["text"];
$html.="<input type='{$itme['attr']['type']}' name='{$itme['attr']['name']}' value='{$itme['option']['m']}'>{$itme['option']['m']}";
$html.="<input type='{$itme['attr']['type']}' name='{$itme['attr']['name']}' value='{$itme['option']['w']}'>{$itme['option']['w']}";
}
return $html."<p></p>";
}
function select_html($itme){
$html="";
$html.="<select name='{$itme['attr']['name']}'>";
foreach($itme['option'] as $k=>$v){
$html.="<option value='{$k}'>$v</option>";
}
$html.="</select>" ;
return $html."<p></p>";
}
function textarea_html($itme){
$html="";
$html=$itme["text"];
$html.="<textarea name='{$itme['attr']['name']}' cols='{$itme['attr']['cols']}' rows='{$itme['attr']['rows']}'></textarea>";
return $html."<p></p>";
}
`里面有注释
4.2——index。php里面放代码
输出
echo "$html
5.每个PHP里面用连接符]include连接
index。PHP输出结果。