PHP html 和 php 集成(对不起,标题含糊不清)


PHP html and php integration (Sorry for the vague title)

我正在使用php创建另一个.php文件。我是这样做的:

$file = fopen($Title . ".php" ,"w") or die("File Creation error: " . mysql_error());
$textToWrite =
"
<html>'n
<head>'n
&lt;?php include("Header.php") ?&gt;
</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>";