Tôi cố gắng để viết một dòng mới vào một tập tin với PHP và tôi nhận được lỗi sau:Tại sao tôi nhận được lỗi cú pháp trong PHP?
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
Đây là mã của tôi:
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+');
}
}
tôi đã chỉ ra những dòng lỗi xảy ra trên với một bình luận php. Điều gì là sai với dòng này?
Ví dụ về lang_contents:
<?php
$lang['1234'] = 'Restaurants';
Ví dụ về new_contents:
<?php
$lang['1234'] = 'Restaurants';
$lang['1235'] = 'Transportation';
Bạn gần như đã có ... nhưng $ lang được cho là có nghĩa đen. – ShoeLace1291