<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.exec.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.escapeshellarg.php',
    1 => 'escapeshellarg',
    2 => '把字符串转义为可以在 shell 命令里使用的参数',
  ),
  'up' => 
  array (
    0 => 'ref.exec.php',
    1 => '程序执行函数',
  ),
  'prev' => 
  array (
    0 => 'ref.exec.php',
    1 => '程序执行函数',
  ),
  'next' => 
  array (
    0 => 'function.escapeshellcmd.php',
    1 => 'escapeshellcmd',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/exec/functions/escapeshellarg.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.escapeshellarg" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">escapeshellarg</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.3, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">escapeshellarg</span> &mdash; <span class="dc-title">把字符串转义为可以在 shell 命令里使用的参数</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.escapeshellarg-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>escapeshellarg</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$arg</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>escapeshellarg()</strong></span> 将给字符串增加一个单引号并且能引用或者转义任何已经存在的单引号，这样以确保能够直接将一个字符串传入 shell
   函数，并且还是确保安全的。对于用户输入的部分参数就应该使用这个函数。shell 函数包含<span class="function"><a href="function.exec.php" class="function">exec()</a></span>、<span class="function"><a href="function.system.php" class="function">system()</a></span>
   和<a href="language.operators.execution.php" class="link">执行运算符</a> 。
  </p>
  <p class="para">
   在 Windows 上，<span class="function"><strong>escapeshellarg()</strong></span>
   用空格替换了百分号、感叹号（延迟变量替换）和双引号，并在字符串两边加上双引号。此外，每条连续的反斜线(<code class="literal">\</code>)都会被一个额外的反斜线所转义。
  </p>  
 </div>


 <div class="refsect1 parameters" id="refsect1-function.escapeshellarg-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">arg</code></dt>
     <dd>
      <p class="para">
       需要被转义的参数。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.escapeshellarg-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   转换之后字符串。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.escapeshellarg-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>escapeshellarg()</strong></span> 的例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />system</span><span style="color: #007700">(</span><span style="color: #DD0000">'ls '</span><span style="color: #007700">.</span><span style="color: #0000BB">escapeshellarg</span><span style="color: #007700">(</span><span style="color: #0000BB">$dir</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.escapeshellarg-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.escapeshellcmd.php" class="function" rel="rdfs-seeAlso">escapeshellcmd()</a> - shell 元字符转义</span></li>
    <li><span class="function"><a href="function.exec.php" class="function" rel="rdfs-seeAlso">exec()</a> - 执行一个外部程序</span></li>
    <li><span class="function"><a href="function.popen.php" class="function" rel="rdfs-seeAlso">popen()</a> - 打开进程文件指针</span></li>
    <li><span class="function"><a href="function.system.php" class="function" rel="rdfs-seeAlso">system()</a> - 执行外部程序，并且显示输出</span></li>
    <li><a href="language.operators.execution.php" class="link">执行运算符</a></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>