PHP use Backticks as Execution Operators

Posted on December 7th, 2011 by Wayne May in PHP | 0 comments

PHP use backticks as execution operators, which will return the output of to be assigned to a variable. Any code between backticks will be executed as a shell command – the backtick operator is identical to shell_exec()

One example where I found this useful was to get the fully qualified domain name of a server. I could do something like:

1
$fqdn = shell_exec('hostname --fqdn');

or using backticks, I can so something like:

1
$fqdn = `hostname --fqdn`;

Notice that I am using backticks (`) and not single quotes (‘)

Post a comment

Hello guest, care to post a comment?