0

I have this code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title><?php echo $title; ?></title>
</head>
<body>
    <?php foreach ($posts as $post) { ?>
        <div class="post">
            <h3 class="title"><?php $post["title"]; ?></h3>
            <p class="text"><?php $post["text"]; ?></p>
        </div>
    <?php } ?>
</body>
</html>

And I need to include it in other file and execute all the PHP code in it. How can i do it?

Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42
Jan Polak
  • 111
  • 3
  • 10

2 Answers2

4

Include with absolute path :

<?php include($_SERVER["DOCUMENT_ROOT"].'/yourdirectory/yourfile.php'); ?>
Olou
  • 102
  • 12
0

use the include() function.

include("the file.php")
Caspar Wylie
  • 2,818
  • 3
  • 18
  • 32