philip Tue Apr 5 18:04:03 2005 EDT
Modified files:
/phpdoc/en/language control-structures.xml
Log:
include(): Show how to "include a file into a variable",
and see also the auto_(prepend|append)_file directives.
http://cvs.php.net/diff.php/phpdoc/en/language/control-structures.xml?r1=1.114&r2=1.115&ty=u
Index: phpdoc/en/language/control-structures.xml
diff -u phpdoc/en/language/control-structures.xml:1.114
phpdoc/en/language/control-structures.xml:1.115
--- phpdoc/en/language/control-structures.xml:1.114 Tue Apr 5 08:48:05 2005
+++ phpdoc/en/language/control-structures.xml Tue Apr 5 18:04:02 2005
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.114 $ -->
+<!-- $Revision: 1.115 $ -->
<chapter id="language.control-structures">
<title>Control Structures</title>
@@ -1549,11 +1549,40 @@
the included file.
</para>
<simpara>
- A few other ways to "include" files into variables are with
- <function>fopen</function>, <function>file</function> or by using
- <function>include</function> along with
- <link linkend="ref.outcontrol">Output Control Functions</link>.
+ Another way to "include" a PHP file into a variable is to capture the
+ output by using the <link linkend="ref.outcontrol">Output Control
+ Functions</link> with <function>include</function>. For example:
</simpara>
+ <para>
+ <example>
+ <title>Using output buffering to include a PHP file into a string</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$string = get_include_contents('somefile.php');
+
+function get_include_contents($filename) {
+ if (is_file($filename)) {
+ ob_start();
+ include $filename;
+ $contents = ob_get_contents();
+ ob_end_clean();
+ return $contents;
+ }
+ return false;
+}
+
+?>
+]]>
+ </programlisting>
+ </example>
+ </para>
+ <para>
+ In order to automatically include files within scripts, see also the
+ <link linkend="ini.auto-prepend-file">auto_prepend_file</link> and
+ <link linkend="ini.auto-append-file">auto_append_file</link>
+ configuration options in &php.ini;.
+ </para>
¬e.language-construct;