2013/11/10

PHP 執行 Linux 的 Shell Script

PHP 的 shell_exec() 函式可以執行 Linux 的 Shell Script

語法:

string shell_exec ( string $cmd )

範例:

<?php
  $output = shell_exec('ls -l');
  echo '<pre>$output</pre>';
?>
以上指令可以列出目前目錄的檔案列表


案例:用 Shell Script 的 cal 指令來顯示月曆
引用來源:http://www.grandsights.twbbs.org/2010/04/php-shell-script.html

<?php
  $output = shell_exec('/usr/bin/cal 11 2013');
  echo '<pre>$output</pre>';
?>
顯示2013/11月份的月曆

沒有留言:

張貼留言