1

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
}
?>
1
  • sure, it works, but the page included/required can access the index.php file var written before it's inclusion/requirment, not those after Commented Dec 2, 2014 at 18:33

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

But when I just do it using "include" I get only plain text, once the PHP code is not complete in each file! Remember that the "IF" statment is divided in two files!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.