我正在尝试用PHP将新行写入文件,但出现以下错误:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
这是我的代码:
public function add_line($line, $value, $file){
$CI =& get_instance();
$CI->load->helper('file');
foreach($this->existing_langs as $lang){
$lang_contents = read_file($this->lang_path.'/'.$lang.'/'.$file.'_lang.php');
$new_contents = $lang_contents."\n$lang['".$line."'] = '".$value."';"; //Error happens on this line
write_file($this->lang_path.'/'.$lang.'/'.$file.'_lang.php', $new_contents, 'w+');
}
}
我已经指出了使用PHP注释发生错误的那一行。这条线怎么了?
lang_contents示例:
<?php
$lang['1234'] = 'Restaurants';
new_contents的示例:
<?php
$lang['1234'] = 'Restaurants';
$lang['1235'] = 'Transportation';
如果您尝试将$lang
字符串写入文件
$lang_contents."\n".'$lang'."['".$line."'] = '".$value."';";
封闭$lang
与"
将只访问您的$lang
是或不是阵列。因为您$lang
在文件路径中使用。我认为这不是一个数组。因此,使用..."\n$lang['".$line."']...
只会调用$lang
索引为$line
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句