On Wed, 12 Nov 2003 21:25:23 GMT, Tim Tyler <tim@tt1lock.org> wrote:
[color=blue]
>Andy Hassall <andy@andyh.co.uk> wrote or quoted:[color=green]
>> On Wed, 12 Nov 2003 20:57:36 GMT, Tim Tyler <tim@tt1lock.org> wrote:[/color]
>[color=green][color=darkred]
>>>Should PHP have allowed ">" to be used within PHP tags?[/color]
>>
>> Yes.
>>[color=darkred]
>>>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.[/color]
>>
>> Only the output of the script has to conform to HTML.[/color]
>
>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?[/color]
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?
[color=blue]
>Is there a work-around - can you go:
>
><?php
>// <!--
>if (a > b) {
>// -->
>?>
>
>...or something?[/color]
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.
[color=blue][color=green]
>> Actually that's not even true; nobody is limiting you to outputting
>> just HTML or XHTML with PHP; you can output whatever you like.[/color]
>
>Well yes - but what does the "H" in "PHP" stand for? ;-)[/color]
Hypertext. Not all hypertext is HTML ;-p
Should command-line PHP scripts be HTML encoded? ;-p
if ($a && $b) anyone? Yuk!
--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (
http://www.andyh.co.uk)
Space: disk usage analysis tool (
http://www.andyhsoftware.co.uk/space)