By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

">"

P: n/a
Should PHP have allowed ">" to be used within PHP tags?

e.g. in:

if (a > b) { ... };

....and...

$object -> member;

The use of ">" stops PHP pages being valid HTML/XML - by ending
the current HTML tag - which prevents page validation and the
use of conventional formatting tools or parsers.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #1
Share this Question
Share on Google+
20 Replies


P: n/a
On Wed, 12 Nov 2003 20:57:36 GMT, Tim Tyler <ti*@tt1lock.org> wrote:
Should PHP have allowed ">" to be used within PHP tags?
Yes.
e.g. in:

if (a > b) { ... };

...and...

$object -> member;

The use of ">" stops PHP pages being valid HTML/XML - by ending
the current HTML tag - which prevents page validation and the
use of conventional formatting tools or parsers.


Only the output of the script has to conform to HTML. Actually that's not even
true; nobody is limiting you to outputting just HTML or XHTML with PHP; you can
output whatever you like.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2

P: n/a
Andy Hassall (63.620% quality rating):

Only the output of the script has to conform to HTML. Actually that's
not even true; nobody is limiting you to outputting just HTML or
XHTML with PHP; you can output whatever you like.


I output NNTP ;)

/joe
--
Thomas Annandale is worthless and great.
Jul 17 '05 #3

P: n/a
Andy Hassall <an**@andyh.co.uk> wrote or quoted:
On Wed, 12 Nov 2003 20:57:36 GMT, Tim Tyler <ti*@tt1lock.org> wrote:
Should PHP have allowed ">" to be used within PHP tags?


Yes.
e.g. in:

if (a > b) { ... };

...and...

$object -> member;

The use of ">" stops PHP pages being valid HTML/XML - by ending
the current HTML tag - which prevents page validation and the
use of conventional formatting tools or parsers.


Only the output of the script has to conform to HTML.


It prevents users from using existing HTML tools to handle PHP - files -
such as:

Web browsers;
Syntax highlighting;
Parsers;
Formatters;
Lint tools;

Were using ">=" and "->" really important enough to justify
violating the HTML specifications?

Is there a work-around - can you go:

<?php
// <!--
if (a > b) {
// -->
?>

....or something?
Actually that's not even true; nobody is limiting you to outputting
just HTML or XHTML with PHP; you can output whatever you like.


Well yes - but what does the "H" in "PHP" stand for? ;-)
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #4

P: n/a
Tim Tyler wrote on Wednesday 12 November 2003 13:25:
It prevents users from using existing HTML tools to handle PHP - files -
such as:

Web browsers;
Syntax highlighting;
Parsers;
Formatters;
Lint tools;

Were using ">=" and "->" really important enough to justify
violating the HTML specifications?


I don't know what browsers, parsers, or syntax highlighters you are
referring to, but <?php is a PI in XML, and all of those should be aware of
that.

I have no such problems with my editor's hightlighter.

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Jul 17 '05 #5

P: n/a
While thinking about how cool Lee Majors was, Tim Tyler blurted:

It prevents users from using existing HTML tools to handle PHP - files -
such as:
Maybe you should use PHP tools or general programming tools rather than
HTML tools. You're not editing straight HTML.
Web browsers;
Web browsers should not be seeing PHP files, just their output.
Syntax highlighting;
Not if you have the proper syntax highlighting rules.
Parsers;
Not if you have the proper grammar for your parser.
Formatters;
Lint tools;
See above, though I'm not sure why you'd use that stuff for PHP.
Were using ">=" and "->" really important enough to justify
violating the HTML specifications?


Are you going to invent new symbols for standard operators??

if($a ^^ $b) // it's "greater than", trust me...

/joe
--
Git.talk.music.emo is beautiful... Matt Hufstetler bogarts Eighth Street
West and the fetus pot pie. A zen koan from gtpj is kludgy in git.general!
The hoppy stack is red and odd.
Jul 17 '05 #6

P: n/a
On Wed, 12 Nov 2003 21:25:23 GMT, Tim Tyler <ti*@tt1lock.org> wrote:
Andy Hassall <an**@andyh.co.uk> wrote or quoted:
On Wed, 12 Nov 2003 20:57:36 GMT, Tim Tyler <ti*@tt1lock.org> wrote:
Should PHP have allowed ">" to be used within PHP tags?


Yes.
The use of ">" stops PHP pages being valid HTML/XML - by ending
the current HTML tag - which prevents page validation and the
use of conventional formatting tools or parsers.


Only the output of the script has to conform to HTML.


It prevents users from using existing HTML tools to handle PHP - files -
such as:

Web browsers;
Syntax highlighting;
Parsers;
Formatters;
Lint tools;

Were using ">=" and "->" really important enough to justify
violating the HTML specifications?


But PHP source code is not written in HTML.

It may have sections in the file that are literal HTML, but that's because
what PHP _really_ does is allows you to embed HTML in the source code, outside
the <?php ?> tags - rather than embed PHP in HTML as is generally claimed; so
you do have some grounds for your argument, but in practice it'd be a real pain
if PHP source code had to be HTML encoded.

Odds are you have HTML elements being output in loops etc.; so even the
sections that are literal HTML may not validate without the actual output of
executing the PHP.

You can use '>' in ASP source code as well - and why not?
Is there a work-around - can you go:

<?php
// <!--
if (a > b) {
// -->
?>

...or something?


If that's what keeps your validator/parser/highlighter happy. I'd have thought
it would complain about <?php first.

http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4 seems to indicate that
the following would be OK, and it passes the W3C HTML validator:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test</title>
</head>
<body>
<!--
<?php
if (a > b) {
echo 'something';
}
?>
-->
</body>
</html>

That puts all the PHP inside an HTML comment, including the non-HTML <?php
tag.

The validator said:

"The uploaded file was checked and found to be valid HTML 4.01 Transitional.
This means that the resource in question identified itself as “HTML 4.01
Transitional” and that we successfully performed a formal validation using an
SGML or XML Parser (depending on the markup language used). "

In fact - just to see what it would complain about - I tried without the
comment markers. It validated OK. If the validator written by the people who
wrote the HTML specification is happy...

PHP doesn't care in the slightest what's 'outside' its tags, so surrounding
the whole lot in HTML comments won't stop it executing.
Actually that's not even true; nobody is limiting you to outputting
just HTML or XHTML with PHP; you can output whatever you like.


Well yes - but what does the "H" in "PHP" stand for? ;-)


Hypertext. Not all hypertext is HTML ;-p
Should command-line PHP scripts be HTML encoded? ;-p

if ($a &amp;&amp; $b) anyone? Yuk!

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #7

P: n/a
Andy Hassall wrote:
On Wed, 12 Nov 2003 20:57:36 GMT, Tim Tyler <ti*@tt1lock.org> wrote:

Should PHP have allowed ">" to be used within PHP tags?

Yes.


Indeed...

But what PHP shouldn't have done was CONTINUE to allow short_open_tags
and worse still, CONTINUE to set the default value to "on" ... so now
this produces a runtime error:

<?xml version="1.0"?>
<?xml-stylesheet href="la la la" ?>
<myRootElement>
<?php // produce XML here ?>
</myRootElement>

If short open tags were banned altogether, then updating old scripts
would be as easy as running a mass search/replace on "<?" with "<?php"

consequently, the "<?php" notation would/does conform perfectly to the
XML notation for a processing instruction. And given that these tags
("<?php" and "?>") do indeed contain processing instructions for the PHP
processor, it would be a very elegent integration to XML and XHTML (the
latest browser standards from the W3C).

Instead we have the short_open_tag mess >:(

Jul 17 '05 #8

P: n/a
Tim Tyler <ti*@tt1lock.org> wrote:
Should PHP have allowed ">" to be used within PHP tags? e.g. in: if (a > b) { ... }; ...and... $object -> member; The use of ">" stops PHP pages being valid HTML/XML - by ending
the current HTML tag - which prevents page validation and the
use of conventional formatting tools or parsers.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.


Ohhhhh I see, for the purpose of your formatter :)
Well there needs to be a new version of your formatter
or configuration that understands the embedded php.
Bet it already exhists?
-Walt

--
Reply to innkeepATcapitalDOTnet to email questions.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #9

P: n/a
Tim Tyler <ti*@tt1lock.org> wrote:
The use of ">" stops PHP pages being valid HTML/XML - by ending
the current HTML tag - which prevents page validation and the
use of conventional formatting tools or parsers.


???

If you want to generate valid xml containing valid php:

<?xml version='1.0'?>
<phpsnippet>
<![CDATA[
<?php
if($a>$b)
{
echo 'foo';
}
?>
]]>
</phpsnippet>

If you want to treat php as valid xml you'll have a bigger problem with
the '<?php' processing instruction than with the characters that should
be xml entities used within the php code.

--

Daniel Tryba

Jul 17 '05 #10

P: n/a
Tim Tyler wrote:
The use of ">" stops PHP pages being valid HTML/XML - by ending
the current HTML tag - which prevents page validation and the
use of conventional formatting tools or parsers.


I fail to see the value in checking PHP code with an X?HTML
validator.

You can validate the *output* with an html validtion tool
with no problems.

If you want to use the online variants, you simply need to
1 - upload the output
2 - make the relevant webserver public

You can even download and install the w3c's html validation
tools so that you can check your output without having to make
it pulicly available.

Of yes, you can think about things a little.

I do agree, though, that maybe dropping the whole short tags
thing might be a good idea...
Matt
Jul 17 '05 #11

P: n/a
Daniel Tryba <ne****************@canopus.nl> wrote or quoted:
If you want to treat php as valid xml you'll have a bigger problem with
the '<?php' processing instruction than with the characters that should
be xml entities used within the php code.


There's that as well - but in my experince, the ">" problem is the one
with the most unpleasant side effects - since most parsers, etc. ignore
tags they don't recognise.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #12

P: n/a
Disco Plumber <sc**@moralminority.org> wrote or quoted:
[...] Tim Tyler blurted:

Were using ">=" and "->" really important enough to justify
violating the HTML specifications?


Are you going to invent new symbols for standard operators??

if($a ^^ $b) // it's "greater than", trust me...


One option would have been to do it fortran's way - using .gt. and .ge.

As for "->" - that is an abomination anyway.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #13

P: n/a
Terence wrote:
consequently, the "<?php" notation would/does conform perfectly to the
XML notation for a processing instruction.
Hmm. A Processing Instruction (PI) in XML (XML1.0 sec. 2.6,
especially production 16), and so XHTML too, begins at "<?" and ends
at the first occurrence of "?>". If the string "?>" appeared within
the PHP code, the processing instruction would be (prematurely)
closed, and the remaining text wouldn't be part of the processing
instruction.

Trying to validate PHP files against an HTML DTD is equally
problematic. Processing Instruction Close (PIC) in HTML is simply
">". So any occurrence of ">" closes the processing instruction. No
amount of hiding or commenting-out changes that fact. Thus the absurd
notion that ">" shouldn't be allowed within PHP code is akin to
arguing that PHP shouldn't allow strings.

Remember what the second P in PHP stands for? ;-)
Instead we have the short_open_tag mess >:(


Unfortunately.

--
Jock
Jul 17 '05 #14

P: n/a
Tim Tyler (8.660% quality rating):

One option would have been to do it fortran's way


You should realize that this sentence should never be written :)

/joe
--
Elflady digs on Shad Hashmi, and then spars with the bonch. In Publix, the
terrorist cell is cantankerous. The blog is huggable and worthless.
Jul 17 '05 #15

P: n/a
In article <f6********************************@4ax.com>,
Andy Hassall <an**@andyh.co.uk> wrote:

: Odds are you have HTML elements being output in loops etc.; so even the
:sections that are literal HTML may not validate without the actual output of
:executing the PHP.

Indeed. A blank form page might validate, but one should really check
the output of a submitted form. Copy/paste "view source" works for me,
saved as a text file, uploaded to The Validator.

The w3c validator ignores php anyway, it seems. I validate for strict
xhtml, using PHP in all sorts of strange and untutored ways, and I get
good results. PHP also has all sorts of obscure functions for stripping
and adding and escaping and unescaping HTML entities.
--
Looks like more of Texas to me.
.... Arizona, where the nights are warm and the roads are straight.
Jul 17 '05 #16

P: n/a
Hi!

Tim Tyler <ti*@tt1lock.org> schrieb:
Only the output of the script has to conform to HTML.
It prevents users from using existing HTML tools to handle PHP - files -
such as:

Web browsers;
Syntax highlighting;
Parsers;
Formatters;
Lint tools;


It's PHP, not HTML! So why do you mix up PHP and HTML. It's PHP, not
HTML! Use a template system and all is well. It's PHP, not HTML!
Were using ">=" and "->" really important enough to justify
violating the HTML specifications?


Yes. It's PHP, not HTML! You can output HTML with PHP. It's PHP, not
HTML! If you know what you're doing, the resulting page will validate.
It's PHP, not HTML!
Actually that's not even true; nobody is limiting you to outputting
just HTML or XHTML with PHP; you can output whatever you like.


Well yes - but what does the "H" in "PHP" stand for? ;-)


"H" means Hypertext, not HTML. It's PHP, not HTML!

Regards,
Matthias

P.S.: It's PHP, not HTML! :-)
Jul 17 '05 #17

P: n/a
On Thu, 13 Nov 2003 17:45:04 +0100, Matthias Esken wrote:
P.S.: It's PHP, not HTML! :-)

LOL!

Is that your final answer? 50 / 50? phone a friend? =)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.

Jul 17 '05 #18

P: n/a
John Dunlop wrote:
Terence wrote:

consequently, the "<?php" notation would/does conform perfectly to the
XML notation for a processing instruction.

Hmm. A Processing Instruction (PI) in XML (XML1.0 sec. 2.6,
especially production 16), and so XHTML too, begins at "<?" and ends
at the first occurrence of "?>". If the string "?>" appeared within
the PHP code, the processing instruction would be (prematurely)
closed, and the remaining text wouldn't be part of the processing
instruction.


hmmm, I suppose you're right.
one could have for instance
<?php echo '?>'; ?>
Trying to validate PHP files against an HTML DTD is equally
problematic. Processing Instruction Close (PIC) in HTML is simply
">". So any occurrence of ">" closes the processing instruction. No
amount of hiding or commenting-out changes that fact. Thus the absurd
notion that ">" shouldn't be allowed within PHP code is akin to
arguing that PHP shouldn't allow strings.


Lucky for us, no one anywhere has ever argued that ">" should not be
allowed.

;)
Instead we have the short_open_tag mess >:(

Unfortunately.


The inability for embedded PHP to conform to a PI is still no reason to
have other PI's and the XML declaration break the PHP scanner. It is for
this reason that short_open_tag should be banned -- PI conformity aside.
Part of the problem is that this php.ini directive cannot be set at
runtime for obvious reason. Hence it blocks open-source app developers
from using the templating ability of PHP to produce XML without
destroying XML compliance in the process.
ie.
<?php // nasty hack to get around ISPs with short_open_tag on
echo "<"."?xml version=\"1.0\" ?".">";
// this code block MUST begin on line 1 ?>

The above hack means that there is no possibility for the document to be
procssed by an XML parser prior to the PHP parser -- even if the
developer gave up the ability to use "?>" in a string literal.

IMO, this unnecesary feature deparavation is counter to the idea that
PHP is a great "enabler" allowing developers to do more.

I think part of the problem is that XML is relatively new compared to
PHP even though XML is mature and well-established now. They changed the
behaviour of register_globals because it needed to be done even though
it caused inconvenience. In my opinion, having to do a search/replace on
"<?"/"<?php" for OLD SCRIPTS is much less of an inconvenience. People
will have no issues getting used to using "<?php" because it doesn't
actually deprive them of any features as short_open_tags does in the
case of XML.

It's just completely uneccessary.

Jul 17 '05 #19

P: n/a
Tim Tyler wrote:
Should PHP have allowed ">" to be used within PHP tags?

e.g. in:

if (a > b) { ... };

...and...

$object -> member;

The use of ">" stops PHP pages being valid HTML/XML - by ending
the current HTML tag - which prevents page validation and the
use of conventional formatting tools or parsers.


It might break HTML, but it doesn't break XML because if you use
"<?php", then the entire PHP block can be a valid processing instruction
(provided you don't use the character sequence "?>" in any string
LITERAL). Now this only works if short_open_tags is disabled (see my
rant on abolishing short_open_tag).

As for HTML and HTML validators -- who cares? -- really...
hardly worth breaking from convention.

(did I mention that that character sequence would have to be in a string
LITERAL as opposed to a variable?)

Jul 17 '05 #20

P: n/a
>>> The use of ">" stops PHP pages being valid HTML/XML - by ending
the current HTML tag - which prevents page validation and the
use of conventional formatting tools or parsers.


Only the output of the script has to conform to HTML.


It prevents users from using existing HTML tools to handle PHP -
files - such as:

Web browsers;
Syntax highlighting;
Parsers;
Formatters;
Lint tools;


Hmm not to my experience. My Macromedia Dreamweaver is handling it all
perfectly, even using PHP-specific syntax highlighting for the
php-parts, and the WYSIWYG works too, I can go drag and dropping the
php-script parts. Only problems occur if I would want to (I really dont)
to use wysiwyg when hassling around with some more complicated scripts
containing partial html-elements with conditional output. Even this
could be avoided with good separation of code and visual layout.

Besides its server-side stuff, your web-browser should not even ever see
the php-code, as shouldnt any validators or other such software.

--
Suni

Jul 17 '05 #21

This discussion thread is closed

Replies have been disabled for this discussion.