-3

I tried to write some content in order to write in a php file and in my $content variable i use Heredoc and nowdoc but php tags seems not working and are still shown.

$content = <<< EOT
<?php
    include $_SERVER['DOCUMENT_ROOT'] . '/home/index2.php';
?> 
EOT;

Any ideas ?

Tom
  • 3
  • 2

2 Answers2

4

Try using Output buffering instead of a heredoc:

ob_start();
include $_SERVER['DOCUMENT_ROOT'] . '/home/index2.php';
$content = ob_get_clean();

Reference:

John Conde
  • 217,595
  • 99
  • 455
  • 496
0

You could do this:

$content = "<" . <<< EOT
?php
    include $_SERVER['DOCUMENT_ROOT'] . '/home/index2.php';
> 
EOT;
Dwayne Towell
  • 8,154
  • 4
  • 36
  • 49