<h1>phptags</h1>
Section: Misc. Reference Manual Pages (January 2012)<br>
Updated: BSD/Linux<br>
<a href="#index">Index</a> <a
to Main Contents</a>
<hr>
<p><a name="lbAB"
<h2>NAME</h2>
phptags - Converter for PHP scripts open/close tags
<p><a name="lbAC"
<h2>SYNOPSIS</h2>
<b>phptags</b> [ ] [
<i>path</i> ]
<p><a name="lbAD"
<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>&lt;?php</i> open and <i>?&gt;</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"
<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
<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"
<h2>OPTIONS</h2>
<p>Short options cannot be concatenated. They must be listed
individually.</p>
<p class="c2">Whitespace modification</p>
<dl compact>


<dd>Removes leading or trailing whitespace.</dd>

<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>

<dd>Appends closing ?&gt; tag when missing at end of file.</dd>

<dd>Removes trailing ?&gt; 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>

<dd>Converts short <i>&lt;?</i> tags into long <i>&lt;?php</i>
versions.</dd>

<dd>Converts unneccessary long <i>&lt;?php</i> tags into short
<i>&lt;?</i> or <i>&lt;?=</i> versions. It is not a very clever
method, but should only convert the one-liners into short tags. And
occurences of <i>&lt;?php echo</i> and <i>&lt;? echo</i> or
<i>print</i> become

<dd>Converts all long <i>&lt;?php</i> tags into short <i>&lt;?</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 &lt;?= into long tags in --long mode, as those
are always enabled for newer PHP versions.</dd>

<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>


<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>&lt;?php print</b> variants as <b>echo</b> equivalent for
<b>&lt;?=</b> short conversion.)</dd>
</dl>
<p class="c2">Miscellaneous options</p>
<dl compact>

<dd>Prints help text.</dd>

<dd>Prints phptags version.</dd>

<dd>More output.</dd>

<dd>Debugging messages.</dd>

<dd>Does not print messages in whitespace --warn mode.</dd>

<dd>Does not overwrite processed <i>*.php</i> scripts, but saves
changes into <i>*.php.new</i> filenames.</dd>

<dd>Renames old files to <i>filename.php~</i> prior
overwriting.</dd>

<dd>Dry run. Does not save modified files back.</dd>

<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">&nbsp;</a>
<h2>EXAMPLES</h2>
<dl compact>
<dt><b>phptags</b> <i>--close</i>
<dd>Adds closing tag to any missing *.php files in current
directory.</dd>
<dt><b>phptags</b> <i>--warn</i>
<dd>Traverses given directory and warns of trailing or leading
whitespace.</dd>
<dt><b>phptags</b> <i>-w -s -c</i> <b>index*.php

<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">&nbsp;</a>
<h2>FILES</h2>
An
ordinary php script, that could contain operation parameter
defaults.
<dl compact>
<dd><i>&lt;?php</i><br>
<i>return array(</i><br>
<i>'token' =&gt; 1, 'verbose' =&gt; 1, 'white' =&gt; 1,</i><br>

</dl>
<p><a name="lbAI"
<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

<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">&nbsp;</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 ?&gt; php tag are not an
actual problem. The tokenizer eats a single <i>&lt;NL&gt;</i> or
<i>&lt;CR&gt;</i> or <i>&lt;CRLF&gt;</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"
<h2>BUGS</h2>
<p>Matching for &lt;?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>&lt;?</i> tags in PHP string
context or comments:</p>
<dl compact>
<dd><i>print 'Here &lt;?php and ?&gt; will get mangled.';</i><br>
<br>
<i>print 'Here &lt;? and ?&gt; will get
</dl>
<p>Might be wanted in rare cases. But use the <b>--tokenizer</b>
mode otherwise for maximum resiliency.</p>
<p><a name="lbAL"
<h2>SEE ALSO</h2>
<b><a <b><a href=
<b><a href=

<hr>
<a name="index" id="index">&nbsp;</a>
<h2>Index</h2>
<dl>
<dt><a
<dt><a
<dt><a
<dt><a
<dt><a
<dt><a
<dt><a
<dt><a
<dt><a
<dt><a
<dt><a href="#lbAL">SEE
</dl>
<hr>
This document was created by <a href=
using the manual pages.<br>