Jump to content

[SOLVED] PHP includes


christofurr

Recommended Posts

When you include a PHP script using the include() function, is the included script supposed to have the HTML opening and closing tags?

 

Page:

<html>
<body>
<?php include("script.php"); ?>
</body>
</html>

 

Script.php:

<html>
<body>
<?php echo "Hello World!" ?>
</body>
</html>

 

Or script.php:

<?php echo "Hello World! ?>

Link to comment
Share on other sites

Only if you want them to. For example, if the include is the only HTML on a page, and the rest is all php code than this would be fine. When the actual page is viewed, you don't want to have more than one set of html tags or you will have validation errors.

Link to comment
Share on other sites

include will simply insert what ever is in that file into the doc at that pointer position in the document.  If you want to change out of php to html than you need to have proper tags to do so.  there are 3 kinds of includes

include() (no error just inserts it)

require() (requires the given file and if it can't open it dies)

require_once() (same as require, but if that file has been opened will not open again)

Link to comment
Share on other sites

include will simply insert what ever is in that file into the doc at that pointer position in the document.

 

That's not working for me. When I include a file with PHP commands without opening and closing PHP tags, it outputs the entire script.

 

Still confused, but I'll experiment a little.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.