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 团购折扣计算公式

复制代码 代码如下: $price=$row['price']; //原价 $nowprice=$row['nowprice']; //现价 $jiesheng=$price-$nowp...

php zlib压缩和解压缩swf文件的代码

使用php就不一样了,php包含了zlib的链接库,可以直接使用其相关功能,下面是我写的压缩和结压缩swf文件的例子: //没有加入判断swf文件是否已经压缩,入需要可以根据文件的第一个...

php数组函数序列之array_pop() - 删除数组中的最后一个元素

array_pop()定义和用法 array_pop() 函数删除数组中的最后一个元素。 语法 array_pop(array)参数 描述 array 必需。规定输入的数组参数。 例子...

PHP实现的进度条效果详解

PHP实现的进度条效果详解

本文实例讲述了PHP实现的进度条效果。分享给大家供大家参考,具体如下: 在做采集的时候,想通过php来实现一个进度条功能,谷歌了一下,找了个合适的代码。下面直接上代码: <&...

php显示时间常用方法小结

本文实例讲述了php显示时间常用方法。分享给大家供大家参考。具体分析如下: 一、PHP函数Date()获取当前时间 代码: 复制代码 代码如下:<?php echo $sh...