473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

">"

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
20 2226
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
>>> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String...
1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
7
by: Diandian Zhang | last post by:
Does anyone have an idea, how to do it? Thanks in advance!
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
3
by: Steven.Xu | last post by:
hi everybody, i am useing some classes which in System.Xml to deal with xml document. what can i do if the document include "<" or ">"? Thanks.
5
by: John Nagle | last post by:
This, which is from a real web site, went into BeautifulSoup: <param name="movie" value="/images/offersBanners/sw04.swf?binfot=We offer fantastic rates for selected weeks or days!!&blinkt=Click...
2
by: imonline | last post by:
Hi, I am generating XML and setting it into the string field. Which will be again generated into xml. Now the last xml which has xml in string field converts into "&gt" for the xml which is set...
4
by: dominique | last post by:
Hello All, In a wx GUI, I would like to let the user choose between >, < or =. So, I created a combobox and when the user chooses ">" for instance, I wanted to return (the objective is to send...
1
by: ismailc | last post by:
Hi, I need help please. Update system to to new version & moved on to .Net2 But now my code that worked in my .Net1 xslt does not work. .Net1 fine: <xsl:stylesheet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.