user3787036
user3787036

Reputation: 191

Is it possible to include/require file with part of code in PHP?

I would like to know if its possible to include part of text file as code in PHP not as text.

For example:

**Index.php FILE**
    <?php
    require "part1.php";
    ?>

    <div>HELLO WORKD</div>

    <?php
    require "part2.php";
    ?>


**Part1.php FILE:**

    <?php
    if(0==0) {
      Part2.php FILE:
    }
    ?>


Part2.php FILE
<?php
}
?>

Upvotes: 1

Views: 748

Answers (1)

dors
dors

Reputation: 1152

Absolutely. require, require_once, include and include_once are your friends to enable this. Here is more info about each...

http://php.net/manual/en/function.require.php
http://php.net/manual/en/function.require-once.php
http://php.net/manual/en/function.include.php
http://php.net/manual/en/function.include-once.php

Upvotes: 2

Related Questions