PHP Execution Operator


Introduction

There is one Execution operator defined in PHP. A string inside back-ticks (``) is treated as a DOS command (a shell command in UNIX/Linux) and its output is returned. This operator is similar in operation to shell_exec() function in PHP.

Following code executes DIR command and returns result as string.

Example

<?php
$list=`dir *.php`;
echo "$list";
?>

Output

Following result will be displayed

Volume in drive C is Windows 10
Volume Serial Number is 540D-CE99
Directory of C:\xampp\php
01/27/2016 05:32 PM 18,869 CompatInfo.php
07/08/2020 06:40 PM 64 test.php
07/11/2020 02:13 PM 48 testscript.php
03/30/2013 05:59 PM 1,447 webdriver-test-example.php
4 File(s) 20,428 bytes
0 Dir(s) 178,002,157,568 bytes free

Here is another example of backtick operator. It executes type command

Example

<?php
$list='type testscript.php';
echo "$list";
?>

Output

Following result will be displayed

type testscript.php

Updated on: 19-Sep-2020

890 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements