|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76017 escapeshellarg bad example + other bad examples
Submitted: 2018-02-27 12:30 UTC Modified: -
From: peter dot mlich at volny dot cz Assigned:
Status: Open Package: Documentation problem
PHP Version: 7.2.2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: peter dot mlich at volny dot cz
New email:
PHP Version: OS:


 [2018-02-27 12:30 UTC] peter dot mlich at volny dot cz
From manual page:

Lot of examples is very very bad. I am user. I need see, what function produce on output. Example for escapeshellarg

Example #1 escapeshellarg() example
system('ls '.escapeshellarg($dir));

Ups? Where is data? What do this?

My example:

$name_orig = './history/file_20170526091704.csv';
$name_new  = './actual/file.csv';
$cmd = 'diff -U0 '.escapeshellarg(escapeshellcmd($name_orig)).' '.escapeshellarg(escapeshellcmd($name_new));
echo 'cmd = ' . $cmd;
exec($cmd, $output, $status); // run operation system command

Input csv files:

a;b;c 1;2;3
u;v;w u;v;w
e;f;g 4;5;6
h;i;j 7;8;9

Produce on screen:

cmd = diff -U0 "./history/file_20170526091704.csv" "./actual/file.csv"
(escapeshellarg escape arguments for commmand. Add quotes, "text")

Produce to $output, implode('\n',$output):
(Linux diff command generate difference of files)

--- ./actual/file.csv	Wed May 17 14:18:26 2017
+++ ./history/file_20170526091704.csv	Tue Feb 27 09:54:26 2018
@@ -1 +1 @@
@@ -3,2 +3,2 @@

I dont know, if i need for escape arguments both, escapeshellarg(escapeshellcmd, because, i not see example output for single or both, or not see practical example usage.


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 05 02:01:30 2024 UTC