简体   繁体   中英

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
}
?>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM