mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
include(): Show how to "include a file into a variable",
and see also the auto_(prepend|append)_file directives. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@183691 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
7daa4b26fe
commit
2a432a960e
1 changed files with 34 additions and 5 deletions
|
@ -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 @@ echo $bar; // prints 1
|
|||
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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue