PHP Include Example

Electrohead 0 Tallied Votes 146 Views Share

Example of using INCLUDE to show a nav bar. For beginners. Simply uses include to show an external file (in this case, nav.php) and that's it! You can also include this in another page with a CSS style. The CSS will be automatically included in formatting the INCLUDEd page! :D

<?php
include("navigation.php");
?>
Dani 4,310 The Queen of DaniWeb Administrator Featured Poster Premium Member

If you're goal is to deal with output, you may find that using ob_ is more flexible, as it lets you retrieve the output from external files and store them in variables for later use.

The syntax would be:

<?php
ob_start();
$output = ob_get_contents();
ob_end_clean();
?>

There are also a whole bunch of other ob_ functions. Check the php.net manual for more information.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.