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 'google-analytics.inc' ?>
This includes the contents of the file named "google-analytics.inc" into my PHP page output.
While that PHP include example works just fine, this following PHP include syntax may be more politically correct:
<? include('google-analytics.inc'); ?>
This makes more sense when you think that a series of PHP statements might look like this:
<? // do the include here include('google-analytics.inc'); // 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:
<?php include 'http://www.devdaily.com/'; ?>
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(http://www.devdaily.com/): failed to open stream: no suitable wrapper could be found in /Users/Al/DevDaily/PHP/incl.php on line 4 Warning: include(): Failed opening 'http://www.devdaily.com/' for inclusion (include_path='.:/usr/lib/php') in /Users/Al/DevDaily/PHP/incl.php on line 4