将PHP开始和结束标记放入变量

时间:2013-12-18 01:13:13

标签: php variables

我正在尝试让我的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); 
?>

1 个答案:

答案 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);