©
This document uses PHP Chinese website manual Release
[#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();
?>