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?

1
  • add include 'test.php'; put all the codes there and create a function Commented Aug 30, 2016 at 8:01

2 Answers 2

4

Include with absolute path :

<?php include($_SERVER["DOCUMENT_ROOT"].'/yourdirectory/yourfile.php'); ?>
Sign up to request clarification or add additional context in comments.

1 Comment

I was doing something else wrong, this wasnt the issue but it pointed me in correct directions. Thanks
0

use the include() function.

include("the file.php")

1 Comment

Try require() too

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.