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