PHP: Foreach gibt Werte mehrmals aus?
Verfasst: 26.12.2006, 13:06
Ich bin dabei ein Formular zu programmieren, um die config.inc.php für meine Webseite automatisch generieren zu lassen. Leider funktioniert das ganze nicht. Die Foreach-Schleife scheint Werte mehrmals auszugeben. Hat vielleicht einer von euch eine Anung was das Problem ist? Hier ist der PHP-Code:
Vielen Dank im Vorraus,
mfg,
lionstarr
Code: Alles auswählen
if(isset($_POST['submit'])){
header("Content-Type: text/plain");
$values = $_POST;
foreach($values as $key => $value){
if($key != "submit" ){
$code .= "\$config['".$key."'] = \"".$value."\";\n";
}
echo $code;
}
}
else{
if(file_exists("config.inc.php")){
include_once "config.inc.php";
}
echo "<html><head><title>Make Config</title></head>";
echo "<body>";
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
echo "<table>";
foreach($config as $key => $value){
echo "<tr><td><label for=\"".$key."\">".$key."</label></td><td>";
if(strpos($value,"<") > -1){
echo "<textarea cols=\"80\" rows=\"10\" name=\"".$key."\">".$value."</textarea>";
}
else{
echo "<input type=\"text\" name=\"".$key."\" value=\"".$value."\">";
}
}
echo "<tr><td>Speichern</td><td><input type=\"submit\" name=\"submit\"></td>";
echo "</table></body>";
}
?>
mfg,
lionstarr