PHP - Can I nest includes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    PHP - Can I nest includes?

    Ok. Can I include a PHP file from a file that has been included.
    From the example below, I have a start PHP page with an include to a
    type of template page, and from page 2, I include a 3rd page. The
    first include works, but the page 3 is brought in as standard text.
    Is this a PHP limitation, or do I need to make a change to the PHP
    config. file?

    Thanks




    (Page1)

    <? include("page2. php"); ?>

    (Page2)

    <html>

    <head>
    <title>Sans Titre</title>
    <meta http-equiv="content-type" content="text/html;
    charset=iso-8859-1" />
    <meta name="generator " content="HAPedi t 3.1">
    </head>
    <body bgcolor="#FFFFF F">
    <?
    // Your code here
    echo "<hr />\n".
    "HAPedit 3.1.11.111 (September 2005 7:03:30 PM)<p>";
    ?>
    requires("page3 .php");
    </body>

    </html>


    (Page3)

    <?
    $x = 100;
    echo $x." This is a test";
    ?>

  • NC

    #2
    Re: PHP - Can I nest includes?

    David wrote:[color=blue]
    >
    > Can I include a PHP file from a file that has been included.[/color]

    Yes.
    [color=blue]
    > From the example below, I have a start PHP page with an include to a
    > type of template page, and from page 2, I include a 3rd page. The
    > first include works, but the page 3 is brought in as standard text.[/color]

    Well, I am surprised anything is including at all... Take a look:
    [color=blue]
    > (Page2)
    > <html>
    > <head>
    > <title>Sans Titre</title>
    > <meta http-equiv="content-type" content="text/html;
    > charset=iso-8859-1" />
    > <meta name="generator " content="HAPedi t 3.1">
    > </head>
    > <body bgcolor="#FFFFF F">
    > <?
    > // Your code here
    > echo "<hr />\n".
    > "HAPedit 3.1.11.111 (September 2005 7:03:30 PM)<p>";
    > ?>
    > requires("page3 .php");
    > </body>
    > </html>[/color]

    First of all, it it not requires(), but require(). Second, your
    require() statements is outside of any PHP block and inside an
    HTML block; it shouldn't have been executed at all...

    Cheers,
    NC

    Comment

    Working...