note 127664 added to function.shell-exec

From: Date: Sat, 24 Sep 2022 07:50:51 +0000
Subject: note 127664 added to function.shell-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-219610@lists.php.net to get a copy of this message
shell_exec() returns string but when this comes to multiline output it is still a multi line string. $sql = ' SELECT column1 as COLUMN1, column2 as COLUMN2, FROM TABLE_NAME WHERE column3 = "'.addslashes($_POST['column3']).'" '; $command = 'mysql \\ --host='.escapeshellarg(HOSTNAME).' \\ --user='.escapeshellarg(USERNAME).' \\ --password='.escapeshellarg(PASSWORD).' \\ --database='.escapeshellarg(DATABASE).' \\ --execute='.escapeshellarg($sql).' \\ | sed -e \'s/"/""/g ; s/\t/","/g ; s/^/"/g ; s/$/"/g\''; echo shell_exec($command); // execute shell command // Outputs csv with data. "COLUMN1","COLUMN2" "data11","data12" "data21","data22" This can be extended for CSV download with below headers. header("Content-type: text/csv"); header("Content-Disposition: attachment; filename={$filename}"); header("Pragma: no-cache"); header("Expires: 0"); ---- Server IP: 2a02:cb43:8000::1101 Probable Submitter: 185.85.3.173 (proxied: 203.192.195.146) ---- Manual Page -- https://php.net/manual/en/function.shell-exec.php Edit -- https://main.php.net/note/edit/127664 Del: integrated -- https://main.php.net/note/delete/127664/integrated Del: useless -- https://main.php.net/note/delete/127664/useless Del: bad code -- https://main.php.net/note/delete/127664/bad+code Del: spam -- https://main.php.net/note/delete/127664/spam Del: non-english -- https://main.php.net/note/delete/127664/non-english Del: in docs -- https://main.php.net/note/delete/127664/in+docs Del: other reasons-- https://main.php.net/note/delete/127664 Reject -- https://main.php.net/note/reject/127664 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219610) next »