The double-quoted string is evaluated: in your code, php tries to evaluate $lang[ , but this throws an error because php expects $lang (variable) or $lang[n] (array).
What is your desired result?
If you want to get literally $ followed by lang characters, you need to exit $ :
$new_contents = $lang_contents."\n\$lang['".$line."'] = '".$value."';";
If you want to display the contents of the $lang variable, followed by [ , you need to write:
$new_contents = $lang_contents."\n$lang"."['".$line."'] = '".$value."';";
Otherwise, if you want to display the contents of the element of the array $lang[$line] , you need to write:
$new_contents = $lang_contents."\n{$lang[$line]} = '".$value."';";
source share