PHP-Fusion
v.7.01
AP-Fusion
v7.02.05
Pimped-Fusion-AP
v0.09.03
December 15 2024 01:13:13
Авторизация
Логин

Пароль



Вы не зарегистрированы?
Нажмите здесь для регистрации.

Забыли пароль?
Запросите новый здесь.
Мини-чат
Вы должны авторизироваться, чтобы добавить сообщение.

lom
06/04/2018 14:03
Мы рады, ждем девятку. Очень хочется пощупать

Alipapa
27/03/2018 22:16
Всем привет, все неисправности устранили, всё у нас работает

mukaton
30/10/2015 02:37
Не получается ничего скачать. Ошибка Not Found

Alipapa
06/10/2015 23:00
9-я версия php-fusion на подходе, следите за новостями

Alipapa
10/11/2014 11:24
Заметь, я дважды ответил через 3 минуты после вопроса, могли бы уже решить

Последние статьи
· О стабилизаторах нап...
· СМС и Вебмани
· TinyMCE для пользова...
· PCRE (Perl Compatibl...
· PCRE (Perl Compatibl...
Последние активные темы форума
  Темы Просмотров Ответов Последние сообщения
PHP-Fusion 7 Bogatyr - бесп...
Моды, плагины
7811 1 Vveb--ws
08-10-2018 16:47
Php-Fusion v9. Первые впеча...
Вопросы по работе
5058 3 Vveb--ws
25-07-2018 13:46
Появился хэлп по PHP-Fusion...
Вопросы по работе
7224 7 Vveb--ws
25-07-2018 13:42
prestashop&ap-fusion
Вопросы по работе
18378 61 Alipapa
26-08-2014 10:29
Плагин магазина Ap-Shop
Моды, плагины
15400 70 Alipapa
18-08-2014 18:14
TinyMCE
Вопросы по работе
22012 55 Alipapa
27-07-2013 21:57
HTML-5
Моды, плагины
5801 1 Alipapa
15-06-2013 19:47
Мультиязычность в Pimped-Fu...
Ошибки, баги, глюки
6692 4 Papich
16-04-2013 12:39
Pimped-Fusion. Первые впеча...
Ошибки, баги, глюки
23435 127 Alipapa
18-12-2012 10:59
Ищу мод для расстановки код...
Моды, плагины
15655 55 Alipapa
17-09-2012 14:00
Как присоединить файл к лич...
Моды, плагины
8557 3 lom
27-05-2012 18:12
Что мне не нравится в после...
Вопросы по работе
7165 4 Alipapa
27-05-2012 18:08
Проблемы с добавлением кате...
Вопросы по работе
8136 5 Alipapa
27-05-2012 18:06

include()

The include() statement includes and evaluates the specified file.

The documentation below also applies to require(). The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well. Be warned that parse error in required file doesn't cause processing halting.

Files for including are first looked in include_path relative to the current working directory and then in include_path relative to the directory of current script. E.g. if your include_path is ., current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/ and then in /www/include/. If filename begins with ../, it is looked only in include_path relative to the current working directory.

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward.

Пример 16-5. Basic include() example

vars.php
<?php

$color
= 'green' ;
$fruit = 'apple' ;

?>

test.php
<?php

echo "A $color $fruit" ; // A

include 'vars.php' ;

echo
"A $color $fruit" ; // A green apple

?>

If the include occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function. So, it will follow the variable scope of that function.

Пример 16-6. Including within functions

<?php

function foo ()
{
    global
$color ;

    include
'vars.php' ;

    echo
"A $color $fruit" ;
}

/* vars.php is in the scope of foo() so     *
* $fruit is NOT available outside of this  *
* scope.  $color is because we declared it *
* as global.
*/
foo ();                     // A green apple
echo "A $color $fruit" ;    // A green

?>

When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.

If "URL fopen wrappers>" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Прил. L for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.

Внимание

Версии PHP для Windows до PHP 4.3.0 не поддерживают возможность использования удаленных файлов этой функцией даже в том случае, если опция allow_url_fopen включена.

Пример 16-7. include() through HTTP

<?php

/* This example assumes that www.example.com is configured to parse .php
* files and not .txt files. Also, 'Works' here means that the variables
* $foo and $bar are available within the included file. */

// Won't work; file.txt wasn't handled by www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2' ;

// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2' ;

// Works.
include 'http://www.example.com/file.php?foo=1&bar=2' ;

$foo = 1 ;
$bar = 2 ;
include
'file.txt' ;   // Works.
include 'file.php' ;   // Works.

?>
Смотрите также Remote files, fopen() and file() for related information.

Because include() and require() are special language constructs, you must enclose them within a statement block if it's inside a conditional block.

Пример 16-8. include() and conditional blocks

<?php

// This is WRONG and will not work as desired.
if ( $condition )
    include
$file ;
else
    include
$other ;


// This is CORRECT.
if ( $condition ) {
    include
$file ;
} else {
    include
$other ;
}

?>

Handling Returns: It is possible to execute a return() statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. You can take the value of the include call as you would a normal function. This is not, however, possible when including remote files unless the output of the remote file has valid PHP start and end tags (as with any local file). You can declare the needed variables within those tags and they will be introduced at whichever point the file was included.

Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value.

Пример 16-9. Comparing return value of include

<?php
// won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('')
if (include( 'vars.php' ) == 'OK' ) {
    echo
'OK' ;
}

// works
if ((include 'vars.php' ) == 'OK' ) {
    echo
'OK' ;
}
?>

Замечание: In PHP 3, the return may not appear inside a block unless it's a function block, in which case the return() applies to that function and not the whole file.

Пример 16-10. include() and the return() statement

return.php
<?php

$var
= 'PHP' ;

return
$var ;

?>

noreturn.php
<?php

$var
= 'PHP' ;

?>

testreturns.php
<?php

$foo
= include 'return.php' ;

echo
$foo ; // prints 'PHP'

$bar = include 'noreturn.php' ;

echo
$bar ; // prints 1

?>

$bar is the value 1 because the include was successful. Notice the difference between the above examples. The first uses return() within the included file while the other does not. If the file can't be included, FALSE is returned and E_WARNING is issued.

If there are functions defined in the included file, they can be used in the main file independent if they are before return() or after. If the file is included twice, PHP 5 issues fatal error because functions were already declared, while PHP 4 doesn't complain about functions defined after return(). It is recommended to use include_once() instead of checking if the file was already included and conditionally return inside the included file.

A few other ways to "include" files into variables are with fopen(), file() or by using include() along with Output Control Functions.

Замечание: Поскольку это языковая конструкция, а не функция, она не может вызываться при помощи переменных функций

Смотрите также require(), require_once(), include_once(), readfile(), virtual(), and include_path.

Все функции PHP:
Навигация
· Новости
· Статьи
· Скачать
· Форум
· Ссылки
· Категории новостей
· Обратная связь
· Галерея
· Поиск
· CMS AP-Fusion. Отличия от PHP-Fusion
· Javascript справочник
· Техника
Сейчас на сайте
· Гостей: 1

· Пользователей: 0

· Всего пользователей: 453
· Новый пользователь: ZDA
Информеры
Загрузка файлов  +  -
10,265,847 уникальных посетителей Iceberg by Harly