PHP 执行运算符

phpserver side programmingprogramming更新于 2025/7/18 16:22:17

简介

PHP 中定义了一个执行运算符。反引号("`")内的字符串将被视为 DOS 命令(在 UNIX/Linux 中为 Shell 命令),并返回其输出。此运算符的操作类似于 PHP 中的 shell_exec() 函数。

以下代码执行 DIR 命令并以字符串形式返回结果。

示例

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

输出

将显示以下结果

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

这是反引号运算符的另一个示例。它执行 type 命令

示例

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

输出

将显示以下结果

type testscript.php

相关文章