|
|
 |
escapeshellarg (PHP 4 >= 4.0.3, PHP 5) escapeshellarg -- Escapar una cadena a ser usada como argumento del
intérprete de comandos Descripciónstring escapeshellarg ( string arg )
escapeshellarg() agrega comillas sencillas
alrededor de una cadena y rodea de comillas/escapa cualquier
comilla sencilla existente, permitiéndole pasar la cadena
directamente a una función del intérprete de
comandos, y logrando que sea tratada como un solo argumento
seguro. Esta función debe ser usada para escapar argumentos
individuales a funciones del intérprete de comandos que
provienen de la entrada del usuario. Las funciones del
intérprete de comandos incluyen exec(),
system() y el operador de comilla
invertida.
Lista de parámetros
- arg
El argumento que será escapado.
Valores retornados
La cadena escapada.
Ejemplos
Ejemplo 1. Ejemplo de escapeshellarg() |
<?php
system('ls '.escapeshellarg($dir));
?>
|
|
22-May-2006 05:25
Most of the comments above have misunderstood this function. It does not need to escape characters such as '$' and '`' - it uses the fact that the shell does not treat any characters as special inside single quotes (except the single quote character itself). The correct way to use this function is to call it on a variable that is intended to be passed to a command-line program as a single argument to that program - you do not call it on command-line as a whole.
The person above who comments that this function behaves badly if given the empty string as input is correct - this is a bug. It should indeed return two single quotes in this case.
phpnet at lostreality dot org
11-Nov-2005 08:53
This function does not escape $ it seems. This lets user embed shell variables such as $PATH into commands, which you may or may not want to allow. I'm using shell_exec() because I need the entire command as one string, and need access to the stdout data as one string as well.
ludvig dot ericson at gmail dot com
01-Sep-2005 10:17
It seems from my tests that escapeshellarg("`ls -al`") is _NOT_ escaped into \`ls -al\` as it should be.
Anyway, a bash/sh environment does not seem to interprett ` inside of a singleqoute (').
$ echo "`echo hello`"
hello
$ echo '`echo hello`'
`echo hello`
$ echo "\`echo hello\`"
`echo hello`
Just a tip.
18-May-2005 11:37
According to my test (PHP 4.3.10) there is no need to call escapeshellarg() on a filename that is being written to by proc_open, and probably others. E.g.
<?php
$process = proc_open("echo hi",
array(
0 => array("pipe", "r"),
1 => array("file", 'filename with spaces', "w"),
2 => array("pipe", "w"),
),
$pipes);
?>
creates a file named:
filename with spaces
In fact,
<?php
1 => array("file", escapeshellarg('filename with spaces')
?>
creates a file named:
'filename with spaces'
(quotes included in filename.) Maybe all the PHP functions that take a filename as a separate parameter work this way. I guess you just need to escape filenames when they are part of a single string command line such as with the backtick operator, system(), etc.
antony lesuisse
22-Apr-2004 08:30
NOTE: If you are using PHP >= 4.2 you should use the pcntl_* (Process
Control) functions instead of this hack.
PHP, before version 4.2, didn't provide any execl(3)-like or
execv(3)-like methods to invoke external programs, thus everything
goes trough /bin/sh -c and we are forced to quote arguments.
To make it worse escapeshellarg() behaves badly (IMHO) with an empty
string:
<?php
echo "mime-construct --to ".escapeshellarg($to)." --cc a@a.com";
?>
The following function is a wrapper to system(), and it can be adapted
to popen(),exec(),shell_exec():
<?php
function lib_system() {
$arg=func_get_args();
if(is_array($arg[0]))
$arg=$arg[0];
$cmd=array_shift($arg);
foreach($arg as $i) {
$cmd.=" ''".escapeshellarg($i);;
}
system($cmd);
}
lib_system("mime-construct","--output", "--to",$a,"--string",$b);
lib_system(array("mime-construct","--output", "--to",$a,"--string",$b));
?>
vosechu at roman-fleuve dot com
25-Mar-2004 05:05
If escapeshellarg() returned something on a null input it would probably break more programs than it helps. Even if it's two "'s or two ''s, this function wouldn't work the way it's supposed to (that is, returning nothing).
However, most people do not put "" into their commands but I can see where it might be useful at the same time.
Perhaps an option in the command that would return the type of null we want. I might want the null character to be returned, someone else might want '', and someone else might want nothing at all.
php at floris dot nu
26-Mar-2003 07:27
i also thought the output was gonna be between 's because that's the way windows handles arguments with spaces in them. i think we have a unix <> windows misunderstanding here...
jbriggs at esoft dot com
04-Jan-2002 12:57
This function returns nothing when called with an empty argument.
escapeshellarg("b'lah") returns 'b'\''lah'
but escapeshellarg("") returns ""
| |
| | Citas célebres | Supongo que a la mayoría de nosotros el mar nos pone un poco nerviosos. Sea cual sea su sonrisa, dudamos de su amistad. H. M. Tomilson Escritor británico (1873-1958) | | Citas en tu mail | | ©Contenidos Gratis |
| Inicio | Acción | Estrategia | Palabras | Puzzles | Solitarios | Foro Trucos |  | Cake Mania Jugadores: 6835 Categoría del juego: Acción Objetivo del juego: Ayuda a Jill a recuperar la pastelería de su abuela llevando su propia pastelería; consigue clientes y gana dinero. |
|  | Rainbow Web Jugadores: 2199 Categoría del juego: Puzzles Objetivo del juego: Rompe un pegajoso hechizo y salva un reino de fantasía en Rainbow Web. Tendrás toneladas de diversión mientras juegas a este mágico desafío para la mente. |
|  | Mahjongg Fortuna Jugadores: 12462 Categoría del juego: Solitarios Objetivo del juego: Velocidad y habilidad mental son las armas más importantes en esta versión de un antiguo juego asiático. Despeja el tablero lo antes posible haciendo clic en las fichas iguales y gánate la fama eterna de la puntuación más alta. |
|  | Chainz 2 Jugadores: 6955 Categoría del juego: Puzzles Objetivo del juego: Entra en el mundo de las combinaciones con Chainz 2: Relinked, emocionante secuela del exitazo del año pasado, Chainz. Gira eslabones y crea combinaciones de 3 ó más. |
|  | Delicious Jugadores: 4405 Categoría del juego: Acción Objetivo del juego: ¿Eres un as de la multitarea? ¿Quieres que tus clientes estén contentos? ¡Pues Delicious es tu juego! Sacia el apetito de los clientes y tenlos contentos; ¡no te arriesgues! |
|  | Bookworm Jugadores: 4568 Categoría del juego: Palabras Objetivo del juego: Junta las letras para formar palabras. ¡Las palabras más largas valen más puntos! |
|  | Zuma Jugadores: 4976 Categoría del juego: Acción Objetivo del juego: Controla el ídolo de la rana de piedra de los antiguos Zuma en este intrigante enigma de acción. ¡Dispara bolas para formar conjuntos de tres, pero si dejas que lleguen a la calavera dorada morirás! |
|  | Jewel of Atlantis Jugadores: 3798 Categoría del juego: Puzzles Objetivo del juego: Descubre la ciudad hundida de la Atlántida y busca valiosos tesoros. Viaja más allá de las profundidades del mar y vive trepidantes aventuras en Jewel of Atlantis. |
|  | Jewel Quest Jugadores: 3727 Categoría del juego: Puzzles Objetivo del juego: Convierte la arena de la antigua selva en oro tan rápido como puedas juntando grupos de 3 elementos. ¡Los grupos más grandes valen más puntos! |
|  | Bejeweled 2 Jugadores: 3659 Categoría del juego: Puzzles Objetivo del juego: Con cuatro modos de juego únicos y fascinantes, nuevas piezas de juego explosivas e imponentes fondos planetarios, Bejeweled 2 es mucho más adictivo que nunca. |
|
|