0
Ich weiß nicht viel über PHP. Ich habe 3 Dateien in meinem Projekt.ersetzen Zeichenfolge Wert in config.php
erstens ist system.php, die die loch anwendungslogik halten. hier seinen Code:
<?php
require "config/config_system.php";
$config = new Config;
$config-> load('config.php');
// this is way i want to change setting.
echo $config-> replace("db.host" , "replace value");
?>
2. ist config_system.php, die die Konfiguration hält logic.here seinen Code:
<?php
class Config {
protected $data;
protected $informaton;
protected $default;
public function load($file) {
$this->data = require $file;
$this->informaton = require $file;
}
public function find($key, $default = null) {
$this->default = $default;
$segments = explode(".", $key);
$data = $this->data;
foreach ($segments as $segment) {
if (isset($data[$segment])) {
$data = $data[$segment];
} else {
$data = $this->default;
break;
}
}
return $data;
}
public function exists($key) {
return $this->find($key) !== $this->default;
}
// this is the function i am trying to make valide
public function replace($value) {
$arrayvalues = explode(".", $value);
$informaton = $this->informaton;
foreach ($arrayvalues as $arrayvalue) {
if (isset($informaton[$arrayvalue])) {
$informaton = $informaton[$arrayvalue];
}
}
return $arrayvalues;
}
}
?>
und 3. ist config.php, die die Konfigurationen hält.
<?php
return [
"installation" => [
// this is the value I want to change via a function to true.
"create_db" => "false",
"create_table" => "false"
],
"db" => [
"host" => "localhost",
"user_name" => "root",
"password" => ""
]
];
?>
Jetzt möchte ich einige Einstellungen über eine Funktion ändern. Wie kann ich es tun?
Hay Dank für die Antwort. aber die Funktion zeigt einen Fehler an. explode() erwartet mindestens 2 Parameter – sohidulpaltan
Entschuldigung für Tippfehler –