Код: Выделить всё
$directory = "/c/sl/*";
$files = glob($directory);
print_r($files);
foreach ($files as $file) {
$content = file_get_contents($file);
preg_match('/\$_SESSION\["server"\] = "(.*?)";/', $content, $matches_server);
preg_match('/\$_SESSION\["serverName"\] = "(.*?)";/', $content, $matches_serverName);
$template = file_get_contents("template.php");
$template = preg_replace('/\$_SESSION\["server"\] = "(.*?)";/', '$_SESSION["server"] = "' . $matches_server[1] . '";', $template);
$template = preg_replace('/\$_SESSION\["serverName"\] = "(.*?)";/', '$_SESSION["serverName"] = "' . $matches_serverName[1] . '";', $template);
file_put_contents("/c/sl/" . $file . ".php", $template);
echo "Template updated for " . $matches_server[1] . " with " . $matches_serverName[1] . "
";
}
echo "Variables updated successfully!";
Кроме того, появляется сообщение «Переменные успешно обновлены».< /п>
Подробнее здесь: https://stackoverflow.com/questions/783 ... orking-php