我正在使用CI创建一个监视器脚本并使其可下载。通过读取文件并修改预先输入的.ini和.php文件中的锚点生成文件。
但我发现strtr
部分未被修改。
<小时/> 部分
controllers/monitor.php
:
$post = $this->input->post();
$this->load->helper('file');
$monitor_php = read_file('script/monitor.php');
$monitor_php = str_replace(array('___MONITOR_CODE___'), array($monitor['monitor_code']), $monitor_php);
$monitor_ini = read_file('script/monitor.ini');
$monitor_ini = strtr($monitor_ini, $post);
$monitor_ini = str_replace(array('___MONITOR_HOST___' , '___MONITOR_SCRIPT___' , '___MONITOR_REPORT_INTERVAL___'),
array($monitor['monitor_host'], $monitor['monitor_script'], $monitor['monitor_report_erval']),
$monitor_ini);
$this->load->library('zip');
$this->zip->add_data('monitor.php', $monitor_php);
$this->zip->add_data('monitor.ini', $monitor_ini);
$this->zip->download('monitor');
<小时/>
var_export($post);
的结果:
array (
'___OPERATING_SYSTEM___' => 'CentOS 7.2',
'___WEB_SERVICE___' => 'httpd',
'___MYSQL_SERVICE___' => 'mariadb'
)
<小时/> 我有
echo
$ping_ini
,看起来很好,但文件仍未改变。
echo $monitor_ini;
的结果:
[Analyser]
MonitorHost = "localhost"
MonitorScript = "monitor.php"
OperatingSystem = "CentOS 7.2" // Good
ReportInterval = "1800"
[Service]
WebService = "httpd" // Good
MySQLService = "mariadb" // Good
但实际上下载的monitor.ini
是:
[Analyser]
MonitorHost = "localhost"
MonitorScript = "monitor.php"
OperatingSystem = "___OPERATING_SYSTEM___" // nothing changed
ReportInterval = "1800"
[Service]
WebService = "___WEB_SERVICE___" // nothing changed
MySQLService = "___MYSQL_SERVICE___" // nothing changed