Hallo,
Ich möchte in eine Datei folgenden Inhalt speichern:
Ich verwende zum Schreiben folgende Klasse:
Das Problem ergibt sich bei dem folgenden Array:
Ich habe es schon so probiert:
Jedoch wird hier nur der erste Wert genommen. Dann auf diesem Weg:
Hier wird gar kein Wert eingefügt. Über weitere Hinweise zur Lösung des Problems würtde ich mich sehr freuen.
Gruss
Markus
Ich möchte in eine Datei folgenden Inhalt speichern:
PHP-Code:
$custom_settings[0] = "<?\r\n";
$custom_settings[1] = "const Base_Url = '".$base_url."';\r\n";
$custom_settings[2] = "\$brand = '".$brand."';\r\n";
$custom_settings[4] = "\$lang = '".$lang."';\r\n";
$custom_settings[5] = "const DB1 = ['".$db1."'];\r\n";
$custom_settings[6] = "const Version = '".$version."';\r\n";
$custom_settings[7] = "?>";
$custom_settings = implode('', $custom_settings);
PHP-Code:
class fileHandling {
public $handle;
public $error;
// create = 1: anlegen einer neuen Datei erlauben
function __construct($file,$mode,$create) {
$this->error = false;
$this->handle = Server_Path.$file;
if (is_writable($this->handle)) {
if ($create == 0 AND !file_exists($this->handle) ) {throw new Exception('E010S'); $this->error = true; } else {
$this->handle = fopen($this->handle, $mode); }
} else {throw new Exception('E011S'); $this->error = true; }
}
public function write($data) {
if ($this->error == false) { if (!fwrite($this->handle, $data)) { throw new Exception('E012S'); $this->error = true; }}
}
public function close() {
if ($this->error == false) { if (!fclose($this->handle)) { throw new Exception('E013S'); $this->error = true; }}
}
public function delete() {
if ($this->error == false) { if (!unlink($this->handle)) { throw new Exception('E014S'); $this->error = true; }}
}
}
PHP-Code:
$db1 = ['host','user','pw','db'];
PHP-Code:
$custom_settings[5] = "const DB1 = ['".implode(','‚$db1)."'];\r\n";
PHP-Code:
$host = $db1[0];
$custom_settings[5] = "const DB1 = ['".$host."'];\r\n";
Gruss
Markus
Kommentar