𝌔 Fossil Hub
Login | Fossil manual |
phptags tag tidier

Artifact [eae6bf8433]

Artifact eae6bf8433566d225893781220fe46b5f419abb7:

Wiki page [manpage] by mario 2012-01-09 02:59:01.
D 2012-01-09T02:59:01.495
L manpage
U mario
W 8248

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


[
<B>--options</B><I>,...</I>

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

]
<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.)
<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">&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>, </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 closing tags</B>

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

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

<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>, </I><B>--long</B>

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

<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>, </I><B>--all</B><I>, </I><B>--shortall</B>

<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>, </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 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>, </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.
<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 messages in whitespace --warn mode.
<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.


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

<DD>
Dry run. Does not save modified files back.
<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">&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>  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">&nbsp;</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>&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 <B>~/.config/</B>
<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 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">&nbsp;</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>
Z 8f0d0ff91bc2842f5f503e0ad8b40092