php读取或批改配置型文件中指定关键字的值
程序员文章站
2024-02-08 11:43:22
...
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
------解决方案--------------------
------解决方案--------------------
echo preg_replace('/(?
想从一个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('/(?
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
相关文章
相关视频