PHP 执行运算符


简介

PHP 中定义了一个执行运算符。反勾号(``)内的字符串被视为 DOS 命令(UNIX/Linux 中的外壳命令),并且会返回其输出。此运算符的操作类似于 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

更新于: 19-Sep-2020

1K+ 浏览

开启你的 职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.