D 2012-01-09T03:06:34.545
L manpage
P eae6bf8433566d225893781220fe46b5f419abb7
U mario
W 8409
phptags
Section: Misc. Reference Manual Pages (January 2012)
Updated: BSD/Linux
Index Return
to Main Contents
NAME
phptags - Converter for PHP scripts open/close tags
SYNOPSIS
phptags [ --options,... ] [
files, path ]
DESCRIPTION
phptags is a simple rewriting tool for *.php scripts. It
recursively reads through directories or a given list of scripts
and cleans up <?php open and ?> close tags.
It can remove leading and trailing whitespace, or just convert
short tags into long tags, or vice versa (to convert templates for
editing or deployment). Or it removes or adds closing tags.
FILES
- *.php
- Glob patterns can be used to specify a list of files to
process. (The shell usually does the pattern matching, but
unprocessed *.* patterns are also accepted.)
- ./directory/
- Given directories are recursively traversed and searched for
*.php files; php4, php5 and phtml
extensions also accepted.
Both can be combined.
OPTIONS
Short options cannot be concatenated. They must be listed
individually.
Whitespace modification
- -w, --white,
--whitespace
- Removes leading or trailing whitespace.
- -W, --warn
- Just prints warnings when it detects any whitespace (or leading
UTF-8 BOM).
Adding or removing closing tags
- -c, --close
- Appends closing ?> tag when missing at end of file.
- -u, --unclosed
- Removes trailing ?> close tag if present. (Also gets removed
if there should be trailing whitespace.)
Rewriting short or long tags
- -l, --long
- Converts short <? tags into long <?php
versions.
- -s, --short
- Converts unneccessary long <?php tags into short
<? or <?= versions. It is not a very clever
method, but should only convert the one-liners into short tags. And
occurences of <?php echo and <? echo or
print become <?=.
- -a, --all, --shortall
- Converts all long <?php tags into short <?
versions. This is intended for template scripts. You will need the
--shortall option in --tokenizer mode most of the
time, because it cannot differentiate between one-liners and code
blocks.
Behaviour flags
- --php54
- Does not rewrite <?= into long tags in --long mode, as those
are always enabled for newer PHP versions.
- --rx, --regex
- Prefer regex for rewriting short/long tags. This is the
default. Can be ambiguous due to presence of tags within PHP string
context or comments.
- -t, --token,
--tokenizer
- Use tokenizer for rewriting short/long tags. (More reliable,
but may not work when the short_open_tag php.ini
setting hampers the tokenizer behaviour. It's also less judicious
with linebreaks after opening tags than the regex mode, and doesn't
honor <?php print variants as echo equivalent for
<?= short conversion.)
Miscellaneous options
- -h, --help
- Prints help text.
- -V, --version
- Prints phptags version.
- -v, --verbose
- More output.
- -D, --debug
- Debugging messages.
- -q, --quiet
- Does not print messages in whitespace --warn mode.
- --new, --suffix
- Does not overwrite processed *.php scripts, but saves
changes into *.php.new filenames.
- -b, --backup
- Renames old files to filename.php~ prior
overwriting.
- -d, --dry
- Dry run. Does not save modified files back.
- -c, --color
- Colorizes the --warn output on Windows. This is enabled on
BSD/Linux per default; the -c flag instead disables it there.
EXAMPLES
- phptags --close *.php
- Adds closing tag to any missing *.php files in current
directory.
- phptags --warn scripts/
- Traverses given directory and warns of trailing or leading
whitespace.
- phptags -w -s -c index*.php
./templates
- Fixes whitespace, converts into short tags, and adds closing
tag. Works on some index files and all php scripts in given
templates directory.
FILES
/home/$USER/.config/php/phptags.php An
ordinary php script, that could contain operation parameter
defaults.
- <?php
return array(
'token' => 1, 'verbose' => 1, 'white' => 1,
);
ENVIRONMENT
- XDG_CONFIG_HOME (on BSD/Linux), APPDATA (on
Windows)
- Configuration store directory instead of default
~/.config/
- PHPTAGS_CONFIG
- Override to temporarily disable the configuration file.
For example PHPTAGS_CONFIG=. phptags -v will run without
reading the presets.
CAVEATS
ASP style tags and PHPs super long script tags are not
supported. (The regex mode doesn't look for them, and the tokenizer
should leave them alone.)
Single newlines after the closing ?> php tag are not an
actual problem. The tokenizer eats a single <NL> or
<CR> or <CRLF> up. It's only when people
manage to append multiple of them, or intersparsed with spaces and
tabs, that premature output occurs.
BUGS
Matching for <?php tags is case-sensitive. That's incorrect.
PHP tags are case-insensitive. (Like most other identifiers in PHP,
unless you use e.g. an autoloader with systemic misdesigns.)
As mentioned before, the --regex mode is not
context-aware (for -l and -s modes), thus can
erroneously match and rewrite <? tags in PHP string
context or comments:
- print 'Here <?php and ?> will get mangled.';
print 'Here <? and ?> will get mangled.';
Might be wanted in rare cases. But use the --tokenizer
mode otherwise for maximum resiliency.
SEE ALSO
php(1) recode(1) fromdos(1)
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- FILES
- OPTIONS
- EXAMPLES
- FILES
- ENVIRONMENT
- CAVEATS
- BUGS
- SEE ALSO
This document was created by man2html, using the manual pages.
Z 99c4e84042e8799bb2f141a7e8f78922