此代码有什么问题?为什么我不能在fwrite函数中使用“$”?
fwrite($dosya_index,"$al_".$bol_radiopart[1]." = $_POST['".$bol_radiopart[1]."'];");
答案 0 :(得分:2)
这是因为PHP变量在用双引号括起来的字符串中是interpolated。这意味着以双引号中的$
符号开头的单词将作为变量处理,如果存在此变量,则其值将在字符串中替换。转义$符号(\$
)或使用单引号,但不应用插值。
答案 1 :(得分:1)
我并非100%确定您要实现的目标,但我想您是在尝试将某些代码写入文件或其他内容。
如果你想使用$等等,你就可以使用'而不是",像这样:
fwrite($dosya_index,'$al_' . $bol_radiopart[1] . ' = $_POST[' . $bol_radiopart[1] . '];');
答案 2 :(得分:0)
请参见以下示例:
//$write is a handler for the fopen() method you can use any $var you want and encode info too before execute
$write=fopen($filepath,"w") or die ('Something went wrong'); // "w" flag is for read and write mode, create file if doesn't exists and delete file content before write
fwrite($write, $filecontent); //write all data saved in the string "$filecontent" into the file
fclose($write); // close the file