Çalıştırma İşleci

PHP tek bir çalıştırma işlecini destekmektedir: ters tırnak imleri (``). Bunların bildiğiniz tek tırnaklar olmadığına dikkat edin! Ters tırnak imlerinin arasına yazılmış komutları PHP komut satırında çalıştıracak ve çıktısını döndürecektir. Yani, komut satırına birşey çıktılanmaz; ama sonucu bir değişkene atayabilirsiniz. Çalıştırma işleci shell_exec() işlevinin yaptığı işi yapar.

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

Bilginize:

shell_exec() işlevi etkin değilse, çalıştırma işleci etkin değildir.

Bilginize:

Bazı başka dillerin aksine, tek tırnak imlerinin çift tırnaklı dizeler içinde özel bir anlamı yoktur.

add a note add a note

User Contributed Notes 2 notes

up
117
robert
18 years ago
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."
up
68
ohcc at 163 dot com
7 years ago
You can use variables within a pair of backticks (``).

<?php
    $host
= 'www.wuxiancheng.cn';
    echo `
ping -n 3 {$host}`;
?>
To Top