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
https://forums.phpfreaks.com/topic/60862-solved-php-includes/
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
https://forums.phpfreaks.com/topic/60862-solved-php-includes/#findComment-302824
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
https://forums.phpfreaks.com/topic/60862-solved-php-includes/#findComment-302825
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
https://forums.phpfreaks.com/topic/60862-solved-php-includes/#findComment-302832
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.