我正在使用php创建另一个.php文件。我是这样做的:
$file = fopen($Title . ".php" ,"w") or die("File Creation error: " . mysql_error());
$textToWrite =
"
<html>'n
<head>'n
<?php include("Header.php") ?>
</head>'n
//Body of the webpage
</html>'n
";
$textToWrite = htmlspecialchars($textToWrite);
fwrite($file, $textToWrite);
fclose($file);
其中$Title是非空变量。
我开始看到htmlspecialchars
与我想要的完全相反。它不是将>和<转换为>并
我
转换为>你试过使用 html_entity_decode() 吗?
http://ch2.php.net/manual/en/function.html-entity-decode.php
Heredocs和nowdocs允许您使用PHP标签作为字符串数据: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
<? //PHP 5.4+
'file_put_contents(
"$Title.php",
<<<"content"
<html>
<head>
<? include("Header.php"); ?>
//Body of webpage
</html>
content
);
?>
尝试使用:
$textToWrite =
"<html>
<head>
<" . "?php include("Header.php") ?" . ">
</head>
Body of the webpage
</html>";