我有如下原型如何使一個模式修飾符替換iin php文件中的值?
<?php
$config['some_key']='some_value';
$config['some_other_key']='some_other_value';
//End of file config.php
我有獲取和顯示這些變量對管理員的值的文件,然後他改變一些設置,如果他希望這樣的文件。所以我必須更新config.php文件以保存更改。例如some_value
必須改變以new_value
這樣的:
<?php
$config['some_key']='new_value';
$config['some_other_key']='some_other_value';
//End of file config.php
我研究了一點,發現了我的一個選項是使用file_get_contents()
讀取文件使用preg_replace()
申請我的變化寫文件再次,但我不知道如何做一個模式和替代我的目的。 我真的很感謝你們的幫助,提前致謝。
無論是讀取還是寫入ini/xml/json文件或使用數據庫,您都無法得到更好的服務嗎? –
我使用codeigniter,並有配置文件和讀取這些文件的配置類,通常的方式來更新codeigniter中的配置文件是打開文件並手動更改它,我想要做的是爲它 – Nero
然後你可以使用一個數據庫來存儲這些值,並有一個鉤子來加載那裏的設置和'get_instance() - > config-> set_item()'它們。也許是[像這樣](http://stackoverflow.com/questions/10674341/reading-codeigniter-config-values-from-database-instead-of-config-file)。 – complex857