php.net |  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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-02-27 12:30 UTC] peter dot mlich at volny dot cz
Description:
------------
---
From manual page: http://www.php.net/function.exec
---

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
<?php
system('ls '.escapeshellarg($dir));
?>
Changelog...

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 @@
-a;b;c
+1;2;3;
@@ -3,2 +3,2 @@
-e;f;g
-h;i;j
+4;5;6
+7;8;9

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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 11:01:36 2019 UTC