0

3.5.7PHP执行运算符

Posted by 撒得一地 on 2015年10月29日 in PHP入门教程

php 支持一个执行运算符:反引号(“)。反引号(“)位于键盘Tab键左上方。php 将尝试将反引号中的内容作为外壳命令来执行,并将其输出信息返回(例如,可以赋给一个变量而不是简单地丢弃到标准输出)。

使用反引号运算符“`”的效果与函数 shell_exec() 相同。需要注意的是,在php中,反引号不能在双引号字符串中使用。 而且,反引号运算符在激活了安全模式或者关闭了 shell_exec() 时是无效的。

实例1:

<?php

$output  = ` ls -al `;

echo  "<pre> $output </pre>" ;

?>

当你在linux下运行时,上面运行后输出类似下面内容:

drwxr-xr-x 121 root root 4096 Oct 28 10:19 .
drwxr-xr-x 121 root root 4096 Oct 28 10:19 ..
-rw-------   1 root root  175 Jun  7  2014 .bash_history
-rwxr-xr-x   1 root root    0 Oct 28 10:19 .dockerenv
-rwxr-xr-x   1 root root    0 Oct 28 10:19 .dockerinit
drwxr-xr-x   2 root root 4096 Sep 14 03:08 bin
drwxr-xr-x   2 root root 4096 Apr 10  2014 boot
drwxr-xr-x   5 root root  380 Oct 28 10:19 dev
drwxr-xr-x 132 root root 4096 Oct 28 10:19 etc
drwxr-xr-x   2 root root 4096 Apr 10  2014 home
drwxr-xr-x  18 root root 4096 Sep 14 04:11 lib
drwxr-xr-x   2 root root 4096 Jun  7  2014 lib64
drwxr-xr-x   2 root root 4096 Jun  7  2014 media
drwxr-xr-x   2 root root 4096 Apr 10  2014 mnt
drwxr-xr-x   2 root root 4096 Jun  7  2014 opt
dr-xr-xr-x 132 root root    0 Oct 28 10:19 proc
drwx------   4 root root 4096 Sep 14 03:11 root
drwxr-xr-x   9 root root 4096 Sep 14 04:10 run
drwxr-xr-x   2 root root 4096 Jun  7  2014 sbin
drwxr-xr-x   2 root root 4096 Jun  7  2014 srv
dr-xr-xr-x  13 root root    0 Oct 28 10:19 sys
drwxrwxrwt   5 root root 4096 Sep 14 04:10 tmp
drwxrwxrwx   2 root root 4096 Oct 28 10:19 usercode
drwxr-xr-x  89 root root 4096 Sep 14 04:11 usr
drwxr-xr-x  80 root root 4096 Sep 14 04:11 var

实例2:

<?php

$output  = ` cd /usr && ls -al `;

echo  "<pre> $output </pre>" ;

?>

运行上面的实例后,输出类似下面的结果:

 total 40
drwxr-xr-x  89 root root 4096 Sep 14 04:11 .
drwxr-xr-x 121 root root 4096 Oct 28 10:37 ..
drwxr-xr-x   2 root root 4096 Sep 14 04:11 bin
drwxr-xr-x   2 root root 4096 Apr 10  2014 games
drwxr-xr-x  38 root root 4096 Sep 14 04:11 include
drwxr-xr-x  85 root root 4096 Sep 14 04:11 lib
drwxr-xr-x  18 root root 4096 Sep 14 03:11 local
drwxr-xr-x   2 root root 4096 Sep 14 04:11 sbin
drwxr-xr-x 216 root root 4096 Sep 14 04:11 share
drwxr-xr-x   2 root root 4096 Apr 10  2014 src

标签:

上一篇:

下一篇:

相关推荐

发表评论

电子邮件地址不会被公开。 必填项已用*标注

9 + 1 = ?

网站地图|XML地图

Copyright © 2015-2024 技术拉近你我! All rights reserved.
闽ICP备15015576号-1 版权所有©psz.