首先抱歉我的英语不好(Swissguy)。 我想制作一个简单的模板脚本,在模板面板组中搜索并将其替换为内容
我的问题是在第20行使用array_search。
include 'config/config.php';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$sql_1 = $conn->query("SELECT name FROM office_template_placeholder");
while($row_1 = mysqli_fetch_object($sql_1)){
$panelgroup[] = $row_1->name;
}
$sql_2 = $conn->query("SELECT * FROM office_content");
while($row_2 = mysqli_fetch_assoc($sql_2)){
$panel_panelgroup[] = $row_2[panelgroup];
$panel_source[] = $row_2[source];
}
if( $source = @file_get_contents( "design.html" )) {
foreach( $panelgroup as $key => $var ){
$position = array_search($var, $panel_panelgroup); //Starts with key = 1 but i need key number 0
if($var == $panel_panelgroup[$position]){
$source = str_replace( "{".$var."}", $panel_source[$position], $source );
}
}
}
echo $source;