您好,欢迎访问一九零五行业门户网

php读取或批改配置型文件中指定关键字的值

php读取或修改配置型文件中指定关键字的值
想从一个linux中的配置文件中读取或修改指定的信息数值,下列是文件的一小部分,大概占全部文件的20分之一,如我想修改gsm.mnc的值为09,或者读取gsm.mnc的值如何操作,不要用读取指定行的方法,因为文件可能添加或者删除信息,行数不确定
# network and cell identity.
# network color code, 0-7
# also set gsm.nccspermitted later in this file.
gsm.ncc 0
# basesation color code, 0-7
gsm.bcc 2
# mobile country code, 3 digits.
# mcc must be 3 digits.  prefix with 0s if needed.
# test code is 460.
gsm.mcc 460
# mobile network code, 2 or 3 digits.
# test code is 00.
gsm.mnc 08
# location area code, 0-65535
gsm.lac 1000
# cell id, 0-65535
gsm.ci 10
# network short name to display on the handset.
# this is optional, but must be defined if you also want to
# send current time-of-day to the phine.
gsm.shortname rz8004
$optional gsm.shortname
# a boolean telling whether or not to show country initials with the name.
gsm.showcountry
$optional gms.showcountry
# assignment type for call setup.
# the default is early assignment.
# if defined, this will cause us to use very early assignment instead.
gsm.vea
$optional gsm.vea
------解决方案--------------------
$string = '# network color code, 0-7
# also set gsm.nccspermitted later in this file.
gsm.ncc 0
# basesation color code, 0-7
gsm.bcc 2
# mobile country code, 3 digits.
# mcc must be 3 digits. prefix with 0s if needed.
# test code is 460.
gsm.mcc 460
# mobile network code, 2 or 3 digits.
# test code is 00.
gsm.mnc 08';
$pattern = '/gsm\.mnc (\d+)/u';
$replacement = '99999';
echo preg_replace($pattern, $replacement, $string);
------解决方案--------------------
echo preg_replace('/(?
其它类似信息

推荐信息