<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">&nbsp;</A>
<H2>NAME</H2>

phptags - Converter for PHP scripts open/close tags
<P>
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>

<B>phptags</B>


[


] [
<I>files</I><B>,

]
<P>
<A NAME="lbAD">&nbsp;</A>
<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>
<A NAME="lbAE">&nbsp;</A>
<H2>FILES</H2>

<DL COMPACT>
<DT><I>*.php</I>

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

</DL>
<P>

Both can be combined.
<A NAME="lbAF">&nbsp;</A>
<H2>OPTIONS</H2>

<P>
Short options cannot be concatenated. They must be listed individually.
<P>
<B>Whitespace modification</B>

<P>
<DL COMPACT>
<DT><B>-w</B><I>,

<DD>
Removes leading or trailing whitespace.
<DT><B>-W</B><I>,

<DD>
Just prints warnings when it detects any whitespace (or leading UTF-8
BOM).
<P>
</DL>
<P>

<B>Adding or removing closing tags</B>

<P>
<DL COMPACT>
<DT><B>-c</B><I>,

<DD>
Appends closing ?&gt; tag when missing at end of file.
<DT><B>-u</B><I>,

<DD>
Removes trailing ?&gt; close tag if present. (Also gets removed if there should
be trailing whitespace.)
<P>
</DL>
<P>

<B>Rewriting short or long tags</B>

<P>
<DL COMPACT>
<DT><B>-l</B><I>,

<DD>
Converts short <I>&lt;?</I> tags into long <I>&lt;?php</I> versions.
<DT><B>-s</B><I>,

<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
<I>&lt;?=</I>.
<DT><B>-a</B><I>,

<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.
<P>
</DL>
<P>

<B>Behaviour flags</B>

<P>
<DL COMPACT>
<DT><B>--php54</B>

<DD>
Does not rewrite &lt;?= into long tags in --long mode, as those are always
enabled for newer PHP versions.
<DT><B>--rx</B><I>,

<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.
<DT><B>-t</B><I>,

<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.)
<P>
</DL>
<P>

<B>Miscellaneous options</B>

<P>
<DL COMPACT>
<DT><B>-h</B><I>,

<DD>
Prints help text.
<DT><B>-V</B><I>,

<DD>
Prints phptags version.
<DT><B>-v</B><I>,

<DD>
More output.
<DT><B>-D</B><I>,

<DD>
Debugging messages.
<DT><B>-q</B><I>,

<DD>
Does not print messages in whitespace --warn mode.
<DT><B>--new</B><I>,

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

<DT><B>-b</B><I>,

<DD>
Renames old files to
<I>filename.php~ </I>prior overwriting.


<DT><B>-d</B><I>,

<DD>
Dry run. Does not save modified files back.
<DT><B>-c</B><I>,

<DD>
Colorizes the --warn output on Windows. This is enabled on BSD/Linux per
default; the -c flag instead disables it there.
<P>
<P>
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>EXAMPLES</H2>

<DL COMPACT>
<DT><B>phptags</B><I>  --close</I><B>  *.php</B>

<DD>
Adds closing tag to any missing *.php files in current directory.
<DT><B>phptags</B><I>  --warn</I><B>

<DD>
Traverses given directory and warns of trailing or leading whitespace.
<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.
<P>
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>FILES</H2>


An ordinary php script, that could contain operation parameter defaults.
<DL COMPACT>
<DT><DD>
<I>&lt;?php</I>

<BR>

<I>   return array(</I>

<BR>

<I>       'token' =&gt; 1, 'verbose' =&gt; 1, 'white' =&gt; 1,</I>

<BR>

<I>   );</I>

</DL>
<P>

<P>
<A NAME="lbAI">&nbsp;</A>
<H2>ENVIRONMENT</H2>

<DL COMPACT>
<DT><I>XDG_CONFIG_HOME</I> (on BSD/Linux), <I>APPDATA</I> (on Windows)

<DD>
Configuration store directory instead of default
<DT><I>PHPTAGS_CONFIG</I>

<DD>
Override to temporarily disable the configuration file.
<BR>

For example <B>PHPTAGS_CONFIG=. phptags -v</B> will run without reading the presets.
<P>
</DL>
<A NAME="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>
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>
<A NAME="lbAK">&nbsp;</A>
<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>
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:
<DL COMPACT>
<DT><DD>
<I>print 'Here &lt;?php and ?&gt; will get mangled.';</I>

<BR>


<BR>

<I>print 'Here &lt;? and ?&gt; will get mangled.';</I>

</DL>
<P>

Might be wanted in rare cases. But use the
<B>--tokenizer</B>

mode otherwise for maximum resiliency.
<P>
<A NAME="lbAL">&nbsp;</A>
<H2>SEE ALSO</H2>

<B><A

<B><A

<B><A

<P>

<HR>
<A
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">FILES</A><DD>
<DT><A HREF="#lbAF">OPTIONS</A><DD>
<DT><A HREF="#lbAG">EXAMPLES</A><DD>
<DT><A HREF="#lbAH">FILES</A><DD>
<DT><A HREF="#lbAI">ENVIRONMENT</A><DD>
<DT><A HREF="#lbAJ">CAVEATS</A><DD>
<DT><A HREF="#lbAK">BUGS</A><DD>
<DT><A HREF="#lbAL">SEE ALSO</A><DD>
</DL>

<HR>
This document was created by
<A
using the manual pages.<BR>