我正在尝试让我的PHP代码编写另一个PHP文件,并且在编写文件时需要打开<?php
并关闭?>
标记。我该怎么做呢?
示例:
$Data = '<?php $keywords = "Testing"; ?>';
完整文件编写代码,不起作用:
<?php
$File = "hello.php";
$Handle = fopen($File, 'w');
$Data = '<?php $keywords = "Testing"; ?>';
fwrite($Handle, $Data);
print "Data Written";
fclose($Handle);
?>
答案 0 :(得分:0)
查看此示例。你是在正确的道路上
$string = '<?php
$dbhost = "'. $_POST["dbhost"]. '";
$dbuname = "'. $_POST["dbuname"]. '";
$dbpass = "'. $_POST["dbpass"]. '";
$dbname = "'. $_POST["dbname"]. '";
$prefix = "'. $_POST["prefix"]. '";
$user_prefix = "'. $_POST["user_prefix"]. '";
$dbtype = "'. $_POST["dbtype"]. '";
?>';
$fp = fopen("config.php", "w");
fwrite($fp, $string);
fclose($fp);