Wiki page
[manpage] by
mario
2014-11-11 12:05:37.
D 2014-11-11T12:05:37.506
L manpage
P b153713d31bd48eb75ed2dbc4c2d2ddb2c110ae9
U mario
W 9937
<H1>phptags</H1>
Section: Misc. Reference Manual Pages (November 2014)<BR>Updated: BSD/Linux<BR>
<P>
<A NAME="lbAB"> </A>
<H2>NAME</H2>
phptags - Converter for PHP scripts open/close tags
<P>
<A NAME="lbAC"> </A>
<H2>SYNOPSIS</H2>
<B>phptags</B>
[
<B>--options</B><I>,...</I>
] [
<I>files</I><B>, </B><I>path</I>
]
<P>
<A NAME="lbAD"> </A>
<H2>DESCRIPTION</H2>
phptags is a simple tool to alterate <B><?php</B>/<B>?></B> tags
in <I>*.php</I> scripts. It recursively reads through directories or a
list of scripts and rewrites them according to specified operations:
<P>
<BR> * Remove whitespace before <B><?</B> or after <B>?></B>.
<BR> * Convert <B><?</B> short open tokens into <B><?php</B> long tags.
<BR> * Or vice versa, long into short tags (for templates).
<BR> * Remove or add <B>?></B> close tokens.
<P>
Which is useful for regular consistency checks, or normalizing
third-party code.
<A NAME="lbAE"> </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.)
<DT><I>./directory/</I>
<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"> </A>
<H2>OPTIONS</H2>
<P>
Short options must be listed individually / unconcatenated, because long
options may start with <B>--</B>double or <B>-</B>single hypen. There are
more flag aliases than summarized here.
<P>
<B>Whitespace modification</B>
<P>
<DL COMPACT>
<DT><B>-w</B><I>, </I><B>--white</B><I>, </I><B>--whitespace</B>
<DD>
Removes leading or trailing whitespace.
<DT><B>-W</B><I>, </I><B>--warn</B>
<DD>
Just prints warnings when it detects any whitespace (or leading UTF-8
BOM).
<P>
</DL>
<P>
<B>Adding or removing close tags</B>
<P>
<DL COMPACT>
<DT><B>-c</B><I>, </I><B>--close</B>
<DD>
Appends closing <I>?></I> token when absent at end of scripts.
<DT><B>-u</B><I>, </I><B>--unclosed</B><I>, </I><B>--open</B><I>, </I><B>--remove-closing</B>
<DD>
Removes trailing <I>?></I> 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>, </I><B>--long</B>
<DD>
Converts short <I><?</I> tags into long <I><?php</I> versions.
The inline-echo <I><?=</I> short tag will be converted too,
unless the <B>--php54</B> flag is used.
<DT><B>-s</B><I>, </I><B>--short</B>
<DD>
Converts unneccessary long <I><?php</I> tags into short <I><?</I> or <I><?=</I> versions. It is
not an overly sophisticated match method, but should only convert one-liners into
short tags. Occurences of <I><?php echo</I> and <I><? echo</I> or <I>print</I> become
<I><?=</I>.
<DT><B>-a</B><I>, </I><B>--all</B><I>, </I><B>--shortall</B>
<DD>
Converts all long <I><?php</I> tags into short <I><?</I> versions. This is
intended for template scripts.
The <B>--tokenizer</B> mode necessitates the <B>--shortall</B> option mostly,
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 <I><?=</I> into long tags in <B>--long</B> mode, as those are always
enabled for PHP versions 5.4 and later. (Not default, because 5.4 still
isn't widespread.)
<DT><B>--php7</B>
<DD>
Probe for <I><%</I> ASP-style tokens, and super long <I><script language=PHP></I> tags.
This is really just a mundane presence check, which does not involve rewriting
or whitespace handling around those seldom tags.
<DT><B>--rx</B><I>, </I><B>--regex</B>
<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>, </I><B>--token</B><I>, </I><B>--tokenizer</B>
<DD>
Use PHPs language tokenizer for rewriting short/long tags.
(This is 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
<I><?php print</I> variants as <I>echo</I> equivalent for <I><?=</I> short conversion.)
<P>
</DL>
<P>
<B>Miscellaneous options</B>
<P>
<DL COMPACT>
<DT><B>-h</B><I>, </I><B>--help</B>
<DD>
Prints help text.
<DT><B>-V</B><I>, </I><B>--version</B>
<DD>
Prints phptags version.
<DT><B>-v</B><I>, </I><B>--verbose</B>
<DD>
More output for rewriting, warnings and also for <B>--help</B>.
<DT><B>-D</B><I>, </I><B>--debug</B>
<DD>
Debugging messages.
<DT><B>-q</B><I>, </I><B>--quiet</B>
<DD>
Does not print additional match infos in whitespace --warn mode, but just
detected files.
<DT><B>--new</B><I>, </I><B>--suffix</B>
<DD>
Does not overwrite processed
<I>*.php </I>scripts, but saves changes into<I> *.php.new</I> filenames.
<DT><B>-b</B><I>, </I><B>--backup</B>
<DD>
Renames old files to
<I>filename.php~ </I>prior overwriting.
<B>Warning:</B> This won't save multiple old versions. Just the last one gets copied.
<DT><B>-d</B><I>, </I><B>--dry</B>
<DD>
Dry run. Does not save modified files back.
<DT><B>-r</B><I>, </I><B>--recursive</B>
<DD>
Specified directories are recursively scanned in any case. This behaviour
can actually only be influenced in the phptags source, or overriden per
config file.
<DT><B>-c</B><I>, </I><B>--color</B>
<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"> </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> scripts/</B>
<DD>
Traverses given directory and warns of trailing or leading whitespace.
<DT><B>phptags</B><I> -w -s -c</I><B> index*.php ./templates</B>
<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"> </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>
<DT><DD>
<I><?php</I>
<BR>
<I> return array(</I>
<BR>
<I> 'token' => 1, 'verbose' => 1, 'white' => 1,</I>
<BR>
<I> );</I>
</DL>
<P>
Internal flag names mostly match the long CLI parameter names. See <B>-D</B>
debug output for reference.
<P>
<A NAME="lbAI"> </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 <B>~/.config/</B>
<DT><I>PHPTAGS_CONFIG</I>
<DD>
More specific override to temporarily change the configuration file
location / or thereby disable processing it.
<BR>
For example <B>PHPTAGS_CONFIG=. phptags -v</B> will run without reading the presets.
<P>
</DL>
<A NAME="lbAJ"> </A>
<H2>CAVEATS</H2>
<P>
Single newlines after the closing ?> php token are not an actual problem for
PHP. The parser/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 it can accrue as premature output.
<P>
ASP style <I><%</I> tags and PHPs super long <I><script></I> tags are never rewritten.
(Way too uncommon to warrant fringe support. The check just exists because of their
removal with PHP "7", or PHP "8" depending on any prematurely printed books.)
<P>
<A NAME="lbAK"> </A>
<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>
As mentioned before, the
<B>--regex</B>
mode is not context-aware
(for<B> --long </B>and<B> --short </B>modes),
thus can erroneously match and rewrite <I><?</I> tags
in PHP string context or comments:
<DL COMPACT>
<DT><DD>
<I>print 'Here <?php and ?> will get mangled.';</I>
<BR>
<BR>
<I>print 'Here <? and ?> will get mangled.';</I>
</DL>
<P>
Which might actually be desirable in some cases. But use the
<B>--tokenizer</B>
mode otherwise for maximum resiliency.
<P>
<A NAME="lbAL"> </A>
<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)
<P>
<HR>
<A NAME="index"> </A><H2>Index</H2>
<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 HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 12:03:40 GMT, November 11, 2014
Z 0a4aa418169535add2a5c37e1f301cc2