使用PHP脚本在服务器上创建PHP文件时出错
我正在尝试制作一个PHP脚本,用于在我的服务器上创建PHP文件,但出现以下错误:使用PHP脚本在服务器上创建PHP文件时出错,php,Php,我正在尝试制作一个PHP脚本,用于在我的服务器上创建PHP文件,但出现以下错误: 解析错误:语法错误,第3行的/home/judiesst/public\u html/77/create.php中出现意外的T_字符串 下面是在服务器上创建php文件的PHPScipt <?php $filename = 'test.php'; $somecontent = "<?php $jdst_xx = "HELLO"; ?>\n"; // Let's make sure the file
解析错误:语法错误,第3行的/home/judiesst/public\u html/77/create.php中出现意外的T_字符串
下面是在服务器上创建php文件的PHPScipt
<?php
$filename = 'test.php';
$somecontent = "<?php $jdst_xx = "HELLO"; ?>\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
更改
$somecontent = "<?php $jdst_xx = "HELLO"; ?>\n";
$somecontent=“\n”;
到
$somecontent=“\n”;
每当双引号内有双引号时,您需要将其转义或用单引号替换
所以你可以用这样的东西
$somecontent = "<?php $jdst_xx = \"HELLO\"; ?>\n";
$somecontent=“\n”;
或
$somecontent=“\n”;
谢谢,如何让这个脚本重写输出文件中的内容,现在只需将新内容与以前的内容(在相同的文件中)合并即可
$somecontent = "<?php $jdst_xx = \"HELLO\"; ?>\n";
$somecontent = "<?php $jdst_xx = 'HELLO'; ?>\n";