PHP include syntax examples

PHP FAQ: Can you show an example of how to use the PHP include syntax? Also, can you show an example of how to include HTTP content into a PHP script?

PHP include syntax to include a file

Sure, I just used the PHP include statement in developing a Drupal theme, and a simple form of the PHP include syntax to include a file looks like this:

<? include '' ?>

This includes the contents of the file named "" into my PHP page output.

While that PHP include example works just fine, this following PHP include syntax may be more politically correct:

<? include(''); ?>

This makes more sense when you think that a series of PHP statements might look like this:

// do the include here

// do something else here
echo "More HTML here ...";

HTML PHP include syntax

Depending on your PHP system configuration, you may also be able to easily include HTTP content in your PHP page, using the HTML PHP include syntax:


include '';


However, if your system is not configured properly, you'll get an error message that looks something like this:

Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /Users/Al/DevDaily/PHP/incl.php on line 4

Warning: include( failed to open stream: no suitable wrapper could be found in /Users/Al/DevDaily/PHP/incl.php on line 4

Warning: include(): Failed opening '' for inclusion (include_path='.:/usr/lib/php') in /Users/Al/DevDaily/PHP/incl.php on line 4