rdelfin
rdelfin

Reputation: 816

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

I am using php to create another .php file. I made it like so:

$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);

where $Title is a non-empty variable.

I have come to see that htmlspecialchars does the exact oposite to what I want. Instead of converting the > and the < to > and < it does the oposite. Is there any other option because puting thr <?php dirrectly gives me a php error. Thank you.

I

Upvotes: 0

Views: 83

Answers (3)

Chase
Chase

Reputation: 29549

Have you tried using html_entity_decode()?

http://ch2.php.net/manual/en/function.html-entity-decode.php

Upvotes: 1

Removed
Removed

Reputation: 1

Heredocs and nowdocs let you use PHP tags as string data: 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
);
?>

Upvotes: 1

Pavel Strakhov
Pavel Strakhov

Reputation: 40492

Try to use:

$textToWrite =
  "<html>
    <head>
      <" . "?php include("Header.php") ?" . ">
    </head>
    Body of the webpage
  </html>";

Upvotes: 0

Related Questions