In PHP, how does include() exactly work?

后端 未结 5 1925
别那么骄傲
别那么骄傲 2020-12-18 01:18

How does include(\'./code.php\'); work? I understand it is the equivalent of having the code \"pasted\" directly where the include occurs, but, for example:

5条回答
  •  情话喂你
    2020-12-18 01:45

    See the manual.

    If you include a text file, it will show as text in the document.

    include does not behave like copy-paste:

    test.php

    
    

    test.txt

    echo $test;
    

    The example above will output:

    **echo $test;**
    

    If you are going to include PHP files, you still need to have the PHP tags and ?>.

    Also, normally parentheses are not put after include, like this:

    include 'test.php';
    

提交回复
热议问题