2

2つの構成ファイルがあります。1つはiniで、もう1つはphpです。以下のようになります。データベースファイル名を更新する必要がありますが、残りのファイルは変更されていない必要があります。そうする方法はありますか?

config.ini

; Turning Debugging on
[test]
developer = true

; Production site configuration data
[production]
database.params.dbname   = /var/lib/firebird/data/radek_db.gdb

およびsetting.php

<?php
/**
The settings file
*/

#This will be done automatically if u want to override it uncomment the next line few lines
/*
    $Path   = 'mainline';

#Database to connect to:
    $Database        =       "radek_db";
?>
4

2 に答える 2

3

file_get_contents()を使用してファイルを文字列に読み取り、str_replace()またはpreg_replace()を実行してから、file_put_contents()を使用して保存できますか?

それらすべてをドキュメントにリンクしますが、複数のリンクを作成するという評判はありません...

編集:あなたが知っているのがオプションの名前だけである場合、preg_matchを使用して正規表現(のようなもの'/^database\.params\.dbname = (.*)$/')でオプション名を見つけてから、見つけた名前に対してstr_replaceを実行できます。

このようなもの:

$file = file_get_contents('/path/to/config/file');
$matches = array();
preg_match('/^database\.params\.dbname = (.*)$/', $file, $matches);
$file = str_replace($matches[1], $new_value, $file);
file_put_contents('/path/to/config/file', $file);
于 2010-07-07T03:17:20.217 に答える
1

iniファイルを読み取るために、がありますparse_ini_file。残りの部分については、その目的のために簡単なスクリプトを作成する必要があります...またはを使用しますsed

于 2010-07-07T00:38:17.960 に答える