Chapter 23 Other Useful Features
The file is echoed to the browser with the text highlighted in various colors depending
on whether it is a string,a comment,a keyword,or HTML.The output is printed on a
background color.Content that doesn’t fit into any of these categories is printed in a
function works similarly,but it takes a string as parameter
and prints it to the browser in a syntax-highlighted format.
You can set the colors for syntax highlighting in your
file.The section you
want to change looks like this:
; Colors for Syntax Highlighting mode
highlight.string = #DD0000
highlight.comment = #FF9900
highlight.keyword = #007700
highlight.bg = #FFFFFF
highlight.default = #0000BB
highlight.html = #000000
The colors are in standard HTML RGB format.
Using PHP on the Command Line
You can usefully write or download many small programs and run them on the com-
mand line.If you are on a Unix system,these programs are usually written in a shell
scripting language or Perl.If you are on a Windows system,they are usually written as a
You probably first came to PHP for a web project,but the same text processing facili-
ties that make it a strong web language make it a strong command-line utility program.
There are three ways to execute a PHP script at the command line:from a file,
through a pipe,or directly on the command line.
To execute a PHP script in a file,make sure that the PHP executable (
depending on your operating system) is in your path and call it with the name
of script as an argument.Here’s an example:
is just a normal PHP file,so it contains any normal PHP syntax
within PHP tags.
To pass code through a pipe, you can run any program that generates a valid PHP
script as output and pipe that to the
executable.The following example uses the
to give a one-line program:
echo ‘<?php for($i=1; $i<10; $i++) echo $i; ?>’ | php
Again, the PHP code here is enclosed in PHP tags (
).Also note that this is
the command-line program
,not the PHP language construct.