Index of /guides/php/examples/command-line-php

[ICO]NameLast modifiedSizeDescription

[PARENTDIR]Parent Directory  -  
[TXT]README.html1998-11-26 10:50 1.7K 
[TXT]arguments.text1998-11-23 16:38 280  
[   ]dump-mysql-test.php2018-05-15 19:30 691  
[TXT]dump-mysql-test.text2018-05-15 19:30 691  
[TXT]input-loop.text1998-11-23 20:20 464  
[TXT]read-input.text1998-11-23 20:20 335  
[TXT]replace.text1998-11-23 18:29 2.7K 
[TXT]simulate-cgi-query.text1998-11-23 16:22 640  
[TXT]test-input.html1998-11-23 18:23 570  
[TXT]test-input.html.SAVE1998-11-23 18:12 545  
[   ]test.php2018-05-15 19:30 386  
[TXT]test.text2018-05-15 19:30 386  

PHP from the command line

These are examples that work from the command line in a shell prompt. This way, PHP can be used as simple scripting language, e.g. to massage files or maintain databases.

Clicking on *.php files above will lead to uninteresting results. You have to copy them locally and have php yourself.

(Note that you need to have installed a non-apache/simple cgi-version of PHP.)

Command line flags for the php executable

Type 'php -h' to see the command-line flags:
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
  -p       Pretokenize a script (creates a .php3p file)
  -e       Execute a pretokenized (.php3p) script
  -c<path> Look for php3.ini file in this directory
  -i       PHP information
  -h       This help

Process arguments

See arguments.text

Basically you have to look into the $argv array.

PHP as preprocessor for static HTML files

 php -q filename.php > filename.html
... and upload filename.html

Note to MS-DOS / Winxx) Users

If you want to play with PHP as a programming language:


D.K.S.