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.