Question

I wrote a little PHP script that performs some MySQL transactions and is supposed to be run locally, instead of making it accessible via the web. I run this script by calling it via the prompt

php script.php param1 param2 param3

The script runs fine and returns the expected results as output to stdout. But the output starts with

Content-type: text/html

in the first line, which obviously is unwanted here. I already managed to change this to plain text

header('Content-type: text/plain; charset=utf-8');

But I don't want this information in my output. How can I suppress it?

Was it helpful?

Solution

Add -q argument like

php -q script.php param1 param2 param3 

to suppress header information.

Running php -h will show you all arguments that it takes.

Usage: php [-q] [-h] [-s [-v] [-i] [-f <file>] | {<file> [args...]}
-q Quiet-mode. Suppress HTTP Header output.
-s Display colour syntax highlighted source.
-f <file> Parse <file>. Implies '-q'
-v Version number
-C Do not chdir to the script directory
-c <path> Look for php.ini file in this directory
-a Run interactively
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-z <file> Load Zend extension <file>.
-l Syntax check only (lint)
-m Show compiled in modules
-i PHP information
-h This help
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top