PHP.mk документација

Извршување

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

language.operators.execution.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека language.operators.execution.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
Извршување

Референца за `language.operators.execution.php` со подобрена типографија и навигација.

language.operators.execution.php

Оператори за извршување

PHP supports one execution operator: backticks (``). Note that these are not single-quotes! PHP will attempt to execute the contents of the backticks as a shell command; the output will be returned (i.e., it won't simply be dumped to output; it can be assigned to a variable). Use of the backtick operator is identical to shell_exec().

Пример #1 Оператор Backtick

<?php
$output
= `ls -al`;
echo
"<pre>$output</pre>";
?>

Забелешка:

Операторот backtick е оневозможен кога shell_exec() е оневозможено.

Забелешка:

За разлика од некои други јазици, backticks немаат посебно значење во низите со двојни наводници.

Дневник на промени

Верзија = NULL
8.5.0 Операторот backtick како псевдоним за shell_exec() е укинат.

Белешки од корисници 3 белешки

robert
20 години пред
Just a general usage note.  I had a very difficult time solving a problem with my script, when I accidentally put one of these backticks at the beginning of a line, like so:

[lots of code]
`    $URL = "blah...";
[more code]

Since the backtick is right above the tab key, I probably just fat-fingered it while indenting the code.

What made this so hard to find, was that PHP reported a parse error about 50 or so lines *below* the line containing the backtick.  (There were no other backticks anywhere in my code.)  And the error message was rather cryptic:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /blah.php on line 446

Just something to file away in case you're pulling your hair out trying to find an error that "isn't there."
ohcc на 163 dot com
пред 9 години
You can use variables within a pair of backticks (``).

<?php
    $host = 'www.wuxiancheng.cn';
    echo `ping -n 3 {$host}`;
?>
paolo.bertani
3 години пред
If you want to avoid situations like the one described by @robert you may want to disable `shell_exec` and -as a consequence- the backtick operator.

To do this just edit the `php.ini` file and add `shell_exec` to the `disable_functions` setting:

    ; This directive allows you to disable certain functions.
    ; It receives a comma-delimited list of function names.
    ; https://php.net/disable-functions
    disable_functions = "shell_exec"

Then you can still use `exec()` to run terminal commands.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.