php-doc-en/reference/exec/functions/escapeshellarg.xml
2021-12-02 17:54:26 +01:00

106 lines
3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- splitted from ./en/functions/exec.xml, last change in rev 1.8 -->
<refentry xml:id="function.escapeshellarg" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>escapeshellarg</refname>
<refpurpose>Escape a string to be used as a shell argument</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>escapeshellarg</methodname>
<methodparam><type>string</type><parameter>arg</parameter></methodparam>
</methodsynopsis>
<para>
<function>escapeshellarg</function> adds single quotes around a string
and quotes/escapes any existing single quotes allowing you to pass a
string directly to a shell function and having it be treated as a single
safe argument. This function should be used to escape individual
arguments to shell functions coming from user input. The shell functions
include <function>exec</function>, <function>system</function> and the
<link linkend="language.operators.execution">backtick operator</link>.
</para>
<para>
On Windows, <function>escapeshellarg</function> instead replaces percent
signs, exclamation marks (delayed variable substitution) and double quotes
with spaces and adds double quotes around the string.
Furthermore, each streak of consecutive backslashes (<literal>\</literal>)
is escaped by one additional backslash.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>arg</parameter></term>
<listitem>
<para>
The argument that will be escaped.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
The escaped string.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>escapeshellarg</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
system('ls '.escapeshellarg($dir));
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>escapeshellcmd</function></member>
<member><function>exec</function></member>
<member><function>popen</function></member>
<member><function>system</function></member>
<member><link linkend="language.operators.execution">backtick operator</link></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->