Under normal circumstances, php is rarely used to execute Linux commands, but under special circumstances, you may use these functions. I used to know that there are two functions that can execute linux commands, one is exec and the other is shell_exec. In fact, there are many. Based on the content of the manual, the following 6 functions are introduced.
1. exec function
<ol class="dp-xml"><li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> </span></span></li><li><span>$</span><span class="attribute">test</span><span> = </span><span class="attribute-value">"ls /tmp/test"</span><span>; //ls是linux下的查目录,文件的命令 </span></li><li class="alt"><span>exec($test,$array); //执行命令 </span></li><li><span>print_r($array); </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>
The return result is as follows:
<ol class="dp-xml"> <li class="alt"><span><span>[root@krlcgcms01 shell]# php ./exec.php </span></span></li> <li><span>Array </span></li> <li class="alt"><span>( </span></li> <li> <span> [0] =</span><span class="tag">></span><span> 1001.log </span> </li> <li class="alt"> <span> [1] =</span><span class="tag">></span><span> 10.log </span> </li> <li> <span> [2] =</span><span class="tag">></span><span> 10.tar.gz </span> </li> <li class="alt"> <span> [3] =</span><span class="tag">></span><span> aaa.tar.gz </span> </li> <li> <span> [4] =</span><span class="tag">></span><span> mytest </span> </li> <li class="alt"> <span> [5] =</span><span class="tag">></span><span> test1101 </span> </li> <li> <span> [6] =</span><span class="tag">></span><span> test1102 </span> </li> <li class="alt"> <span> [7] =</span><span class="tag">></span><span> weblog_2010_09 </span> </li> <li><span>) </span></li> </ol>