PHP系统命令函数使用分析

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

function execute($cmd) {
     $res = '';
     if ($cmd) {
         if(function_exists('system')) {
             @ob_start();
             @system($cmd);
             $res = @ob_get_contents();
             @ob_end_clean();
         } elseif(function_exists('passthru')) {
             @ob_start();
             @passthru($cmd);
             $res = @ob_get_contents();
             @ob_end_clean();
         } elseif(function_exists('shell_exec')) {
             $res = @shell_exec($cmd);
         } elseif(function_exists('exec')) {
             @exec($cmd,$res);
             $res = join(“\n",$res);
         } elseif(@is_resource($f = @popen($cmd,"r"))) {
             $res = '';
             while(!@feof($f)) {
                 $res .= @fread($f,1024);
             }
             @pclose($f);
         }
     }
     return $res;
 }

相关文章

PHP常用函数总结(180多个)

PHP常用函数总结 数学函数 1.abs(): 求绝对值 $abs = abs(-4.2); //4.2 数字绝对值数字 2.ceil(): 进一法取整 echo ceil(9.999)...

为Plesk PHP7启用Oracle OCI8扩展方法总结

注:本文适用于RHEL/CentOS发行版。 步骤1.安装构建自定义PHP 7模块所需的devel包 # yum install plesk-php70-devel gcc gli...

在项目中寻找代码的坏命名

在项目中寻找代码的坏命名

常做的和常想的事情 晦涩的if条件 1)对于||的处理                   &...

PHP 引用是个坏习惯

复制代码 代码如下: function binsearch(&$arr, $key, $value) { $low = 0; $high = count($arr); while ($l...

php实现的中秋博饼游戏之绘制骰子图案功能示例

php实现的中秋博饼游戏之绘制骰子图案功能示例

本文实例讲述了php实现的中秋博饼游戏之绘制骰子图案功能。分享给大家供大家参考,具体如下: 最近公司中秋博饼(在厦门),自己没事也想玩玩,所以就想动手写了一个纯php实现的中秋博饼游戏,...