文字

系统程序执行

  • 简介
  • 安装/配置
    • 需求
    • 安装
    • 运行时配置
    • 资源类型
  • 预定义常量
  • 程序执行 函数
    • escapeshellarg — 把字符串转码为可以在 shell 命令里使用的参数
    • escapeshellcmd — shell 元字符转义
    • exec — 执行一个外部程序
    • passthru — 执行外部程序并且显示原始输出
    • proc_close — 关闭由 proc_open 打开的进程并且返回进程退出码
    • proc_get_status — 获取由 proc_open 函数打开的进程的信息
    • proc_nice — 修改当前进程的优先级
    • proc_open — 执行一个命令,并且打开用来输入/输出的文件指针。
    • proc_terminate — 杀除由 proc_open 打开的进程
    • shell_exec — 通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。
    • system — 执行外部程序,并且显示输出

用户评论:

[#1] ohcc at 163 dot com [2015-11-28 20:34:32]

You can use a pair of backquotes `` to run system commands.

<?php
    header
('Content-Type: text/html; charset=gbk');
    echo `
ping -n 1 www.51-n.com`;// on windows only
?>


it returns the whole output of the command called as a string.

Variables, class properties and return values of class methods   between two ` signs will be replaced with their values.

<?php
    header
('Content-Type: text/html; charset=gbk');
    
$domain 'www.51-n.com';
    echo `
ping -n 1 {$domain}`;
?>


<?php
    header
('Content-Type: text/html; charset=gbk');
    
    class 
Ping {
        
        private 
$domain;
        private 
$count;
        
        public function 
setDomain($domain){
            
$this->domain $domain;
        }
        
        public function 
setCount($count){
            
$this->count $count;
        }

        public function 
getDomain(){
            return 
$this->domain;
        }

        public function 
ping(){
            return `
ping -n {$this->count} {$this->getDomain()}`;
        }

    }
    
    
$p = new Ping;
    
$p->setDomain('www.wuxiancheng.cn');
    
$p->setCount(1);
    echo 
$p->ping();
?>

上一篇: 下一篇: