<?php $table = ($_GET['action']); /*生成後端*/ $fileName="core/Motherboard.php"; $handle=fopen($fileName,"r");//使用打開模式爲r $contents=fread($handle,filesize($fileName));//讀爲二進制 $contents = preg_replace('/\{table\}/', $table, $contents);//替換後臺表名 //查詢表裏的列 $sql = "select COLUMN_NAME from information_schema.COLUMNS where table_name = :table_name and table_schema = '".$config['dbname']."' "; $data = array( ':table_name'=>$table ); $data = $db->queryAll($sql,$data); foreach ($data as $key=>$value){ $arrays[] = " $".$value['COLUMN_NAME']." = \$_REQUEST['".$value['COLUMN_NAME']."']; "; } $field=implode("",$arrays); $contents = preg_replace('/\{field\}/', $field, $contents);//替換後臺列表 foreach ($data as $key=>$value){ $arr[] = " '".$value['COLUMN_NAME']."' => $".$value['COLUMN_NAME'].", "; } $data=implode("",$arr); $contents = preg_replace('/\{data\}/', $data, $contents);//替換後臺列表 /*生成後端*/ $ctxtsubmit=$contents; $f=fopen("action/".$_GET['action'].".php", "wb"); //$text=utf8_encode($ctxtsubmit); //先用函數utf8_encode將所需寫入的數據變成UTF編碼格式。 $text="\xEF\xBB\xBF".$ctxtsubmit; //"\xEF\xBB\xBF",這串字符不可缺乏,生成的文件將成爲UTF-8格式,不然依然是ANSI格式。 fputs($f, $text); //寫入。 fclose($f);