𝌔 Fossil Hub
Login | Fossil manual |
phptags tag tidier

Check-in [29a0f0519b]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Mention hard and soft "close tag" variations; rename BUGS section to "REGEX VS TOKENIZER"
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:29a0f0519b13f91a8cc5a97e746918144db5ee13
User & Date: mario 2014-11-13 19:44:32
Context
2014-11-24
00:23
Added fpm pack: info check-in: a21e117c49 user: mario tags: trunk
2014-11-13
19:44
Mention hard and soft "close tag" variations; rename BUGS section to "REGEX VS TOKENIZER" check-in: 29a0f0519b user: mario tags: trunk
19:43
remove comment check-in: 9f65e1db7d user: mario tags: trunk
Changes

Changes to manpage.1.

1
2
3
4
5
6
7
8
9
..
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
...
198
199
200
201
202
203
204
205
206
207
208
209

210
211
212
213


214
215
216
217
218
219
220
...
225
226
227
228
229
230
231








232
233
234
235




.\" So, it's a frigging fixed problem now.
.\"
.\"
.TH phptags "November 2014" "BSD/Linux" "User Manuals"

.SH NAME
phptags \- Converter for PHP scripts open/close tags

.SH SYNOPSIS
................................................................................
]

.SH DESCRIPTION
phptags is a simple tool to alterate \fB<?php\fP/\fB?>\fP tags
in \fI*.php\fP scripts. It recursively reads through directories or a
list of scripts and rewrites them according to specified operations:

  * Remove whitespace before \fB<?\fP or after \fB?>\fP.
  * Convert \fB<?\fP short open tokens into \fB<?php\fP long tags.
  * Or vice versa, long into short tags (for templates).
  * Remove or add \fB?>\fP close tokens.

Which is useful for regular consistency checks, or normalizing
third-party code.
.SH FILES
................................................................................
.SH CAVEATS

Single newlines after the closing ?> php token are not an actual problem for
PHP. The parser/tokenizer eats a single \fI<NL>\fR or \fI<CR>\fR or \fI<CRLF>\fR
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.

ASP style \fI<%\fR tags and PHPs super long \fI<script>\fR 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.)

.SH BUGS


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



As mentioned before, the
.B --regex
mode is not context-aware
.RB (for " --long " and " --short " modes),
thus can erroneously match and rewrite \fI<?\fP tags
in PHP string context or comments:
................................................................................
.br
.I  "print 'Here <? and ?> will get mangled.';
.P
Which might actually be desirable in some cases. But use the
.B --tokenizer
mode otherwise for maximum resiliency.









.SH "SEE ALSO"
.BR php (1) 
.BR recode (1)
.BR fromdos (1)




|
|







 







|







 







|
|
|

|
>

<
|
|
>
>







 







>
>
>
>
>
>
>
>




>
>
>
>
1
2
3
4
5
6
7
8
9
..
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219
220
221
222
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
.\" Avoid all bickering about PHP close tags
.\" by using an actual and conclusive approach.
.\"
.TH phptags "November 2014" "BSD/Linux" "User Manuals"

.SH NAME
phptags \- Converter for PHP scripts open/close tags

.SH SYNOPSIS
................................................................................
]

.SH DESCRIPTION
phptags is a simple tool to alterate \fB<?php\fP/\fB?>\fP tags
in \fI*.php\fP scripts. It recursively reads through directories or a
list of scripts and rewrites them according to specified operations:

  * Remove whitespace and UTF-8 BOMs before \fI␣\fP\fB<?\fP or after \fB?>\fP\fI␣\fP.
  * Convert \fB<?\fP short open tokens into \fB<?php\fP long tags.
  * Or vice versa, long into short tags (for templates).
  * Remove or add \fB?>\fP close tokens.

Which is useful for regular consistency checks, or normalizing
third-party code.
.SH FILES
................................................................................
.SH CAVEATS

Single newlines after the closing ?> php token are not an actual problem for
PHP. The parser/tokenizer eats a single \fI<NL>\fR or \fI<CR>\fR or \fI<CRLF>\fR
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.

ASP style \fI<%\fR tags and PHPs super long \fI<script>\fR tags are never
rewritten.  (Way too uncommon to warrant fringe support.  The \fB--php7\fR
check just exists because of their removal with PHP 7.)

phptags also doesn't acknowledge `\fI__HALT_COMPILER\fR` tokens in place of
close tags. 


Both the regex and the tokenizer mode now correctly match \fI<?php\fR tags
case-insensitively.

.SH REGEX VS. TOKENIZER

As mentioned before, the
.B --regex
mode is not context-aware
.RB (for " --long " and " --short " modes),
thus can erroneously match and rewrite \fI<?\fP tags
in PHP string context or comments:
................................................................................
.br
.I  "print 'Here <? and ?> will get mangled.';
.P
Which might actually be desirable in some cases. But use the
.B --tokenizer
mode otherwise for maximum resiliency.

The tokenizer on the other hand will ignore "\fBsoft close tags\fR". That is
\fI//?>\fR commented out close tags, which PHP itself never recognizes.
Those might decidedly be applied to eschew rewriting.
.P
They're not a widely known syntactic approach, but can keep php scripts
valid in XML/SGML processing context, are useful for script joining, yet
avoid the effusively feared trailing whitespace issues by themselves.

.SH "SEE ALSO"
.BR php (1) 
.BR recode (1)
.BR fromdos (1)

.IB http://fossil.include-once.org/phptags/

.IB http://stackoverflow.com/a/ 4465825