24 replies [Last post]
samf
samf's picture
Offline
Enthusiast
Los Angeles, CA
Last seen: 8 years 12 weeks ago
Los Angeles, CA
Timezone: GMT-5
Joined: 2003-09-29
Posts: 106
Points: 34

Here are the first 4 lines on the new "strict" pages my company is using:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

problem is the string <? is picked up by PHP and is thought to be the start of a php tag. is there any way to write that first line that would get around this and still be acceptable? Thanks!

[oh, duh, I suppose I could just do this:

<?php echo '<?xml version="1.0" encoding="UTF-8"?>';?>

but still perhaps there's another way without resorting to that, thanks]

Life is complex -- don't make it complicated. If you need help with PHP visit PHP Builder

larmyia
Offline
Elder
London
Last seen: 11 years 47 weeks ago
London
Timezone: GMT+1
Joined: 2005-01-25
Posts: 1060
Points: 0

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

actually with a xhtml 1.0 strict doctype you shouldn't be using the XML prologue at all.

you need to get rid of it.

rmfred
rmfred's picture
Offline
Elder
Rock Springs, WY
Last seen: 1 year 44 weeks ago
Rock Springs, WY
Timezone: GMT-6
Joined: 2004-01-31
Posts: 1073
Points: 31

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Get rid of that first line...

Anonymous
Anonymous's picture
Guru

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Yeah, get rid of the xml prolog. It will just force IE into quirks mode and cause problems anyway.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 31 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

As above but regardless it shouldn't be causing a problem with the php script :? should it! you can only deal with html within php or php within html in one of three ways surely; you either echo/print out the html in which case it should be a string contained in quote marks '<?xml>';
or you come out of php immediately before hand ?><?xml and go back in afterwards or you use 'herdoc' syntax to allow large blocks of html unquoted within php scrip tags, sounds like there may be a fundemental flaw with the scripting, or I'm missing some point in all this Smile

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Anonymous
Anonymous's picture
Guru

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Hugo's correct. It shouldn't be messing with the php script. Most likely a server setting that is picking up "<?" as php instead of "<?php"

I haven't seen a server in a long time that accepted just the "<?" for a php script probably for this very reason. Smile

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 31 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

I guess it's one example of why shorttags are a bad idea.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

gary.turner
gary.turner's picture
Online
Moderator
Dallas
Last seen: 1 min 10 sec ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9761
Points: 3843

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Triumph wrote:
Hugo's correct. It shouldn't be messing with the php script. Most likely a server setting that is picking up "<?" as php instead of "<?php"

I haven't seen a server in a long time that accepted just the "<?" for a php script probably for this very reason. SmileFrom php.ini, under language options,

;Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
short_open_tag = On

As I recall, that's the default. The file, if on a *nix machine compliant with the filesysytem hierarchy standard (FHS), will reside in /etc, likely as /etc/php4/apache/php.ini

As root, open in Emacs or some lesser editor and change On to Off[1]. Do a graceful restart[2] on Apache, and you're good to go. Don't forget to exit to your regular user.

cheers,

gary

[1] If you've been using short tags in your scripting, it might not be a good plan to turn it off Smile

[2] As apposed to Windows, where you must reboot to reconfigure most applications, A graceful restart tells the application to reread the configuration files. The current page being delivered is under the old rules, the next page under the new.

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 31 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

It does appear to be the default :? I had it in mind that you had to set short tags on, all the best practise I've read is not to use them so never have

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

gary.turner
gary.turner's picture
Online
Moderator
Dallas
Last seen: 1 min 10 sec ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9761
Points: 3843

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Back in the day, before reaching my present exalted status, I had the same problem as the OP. The simple cure, as I learned, was not to use the xml declaration.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 31 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Oh exalted one, surely the real answer is not to use the shorttag as often and repeatedly advised by dem learned people, it's why I was confused as to why there was a problem in the first place, didn't cross my mind that shorttags were the cause, but we know I'm slow on the uptake, is there actually any really good reason to use them? other than saving the typing of three characters.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

gary.turner
gary.turner's picture
Online
Moderator
Dallas
Last seen: 1 min 10 sec ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9761
Points: 3843

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Hmmm. A question worthy of the guru. But I will allow my 6 year old granddaughter to answer.

Hi uncle Yugo,

The short taggies won't hurt anything, but the eximel decoration will.

bye,

Emma

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 31 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

I see Emma thing is though you could run into problems if you wanted your scripts to be portable, the problem is that this short tag feature is a 'feature' even if it is enabled by default it remains something that is in addition to the actual way things would work if that feature were turned off, so one could run into the problem of moving a script to a server that had shortags disabled, now where would we be? up the swany I believe is the expression, navigating a certain creek without a paddle with which to escape.

Of course it may also be considered that to remove a perfectly valid piece of code due to the fact that it conflicted with anothers syntax whilst that other syntax was in fact not a required or natural one would not be good practise.

Nothing good ever comes of shortcuts, they make us lazy one must always strive to do things in their fullest there are no shortcuts in life

Now if you would be so good as to pass this on to your grandaddy but be gentle with him he's set in his ways and it may take a while for him to unlearn bad practises, it comes with age I'm afraid Emma
but as you can see now these shorttaggies can be nasty horrible things and you should not play with them

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Anonymous
Anonymous's picture
Guru

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Hugo wrote:
... these shorttaggies can be nasty horrible things and you should not play with them
You mean like matches?

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 7 years 46 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

I normally have short tags off. For templates I'll use apache to turn them on. It keeps template files shorter and neater.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 31 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

But that was one of my queries; what benefit to it's use, does it really keep things neater ? if one is going in and out of php all the time does it not help to focus the eye to where all the starts and stops are if one has a clear <?php , does it really save space/time

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 7 years 46 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

I think so.

Even in my templates I'll use <?php for whole lines of php code. Its much easier to display a variable with <?=$var?> than <?php echo $var?> and in particular makes lines in forms much simpler

<input id="<?=$id?>" name="<?=$name?>" <?=$class?> type="checkbox" <?=$enabled?> value="<?=$value?>" <?=$checked?> />

gary.turner
gary.turner's picture
Online
Moderator
Dallas
Last seen: 1 min 10 sec ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9761
Points: 3843

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Dear uncle Yugo,

My grandaddy says bollocks. I don't know what that means. He said you know. He says just because shorty tag things are there doesn't mean you have to use them. He says that about playing in the street too.

My mommy and daddy just got new sod on the front yard. Why does grandaddy say you should sod off. Don't you want a pretty lawn?

Mommy says we have to go now.

Bye,

Emma

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 20 weeks 5 days ago
Joined: 2004-06-30
Posts: 9668
Points: 801

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Er, . . . what?

Verschwindende wrote:
  • CSS doesn't make pies

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 31 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Hi Emma, grandaddy is just being cantankerous and irascible which just means he's a little grumpy which comes when one reaches ones senior years, but Emma you must not repeat that word to mommy or daddy because your grandaddy will be in a lot of trouble and probably won't be allowed to watch his favorite programme or have his cocoa at bedtime.

Your grandaddy was encouraging - as spring is now upon us - to get out in the garden and sod the lawn, but I do pay particular attention to the lawn and am often heard to remark "sod the lawn" , I trust too that your grandaddy has sodded off to the garden as well, if not could you ask him to withdraw his finger and see to some real work, but make sure he takes his zimmer frame, we don't want him having an accident.

Regarding the shortytagies Emma the problem is that it's not a question of taking a deliberate decision to use them but that they are enabled by default which strikes me as odd, it would make more sense that if you want to use them you should have to deliberately enable them.

I do see though that there is a an benefit as demonstrated by Chris's code example and confess that I had overlooked the shorthand <?= that would make a difference to those html tags where every attribute becomes a variable and thus ends up becoming unnaturally long and hard to read.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

samf
samf's picture
Offline
Enthusiast
Los Angeles, CA
Last seen: 8 years 12 weeks ago
Los Angeles, CA
Timezone: GMT-5
Joined: 2003-09-29
Posts: 106
Points: 34

meanwhile, back at the beginner's forum..

meanwhile, back at the beginner's forum, the "OP" (a new acronym I learned), wonders why a certain question wasn't mentioned/answered, see below:

<div id="obviousQuestion :-)" style="display:none;" onClick="document.getElementById('obviousQuestion :-)').style.display='block';">

why should I not use the xml declaration when the wc3 page I read showed it there? I'd appreciate knowing.

</div>

oops, sorry - you can't click on the div because it has no dimensions..

Life is complex -- don't make it complicated. If you need help with PHP visit PHP Builder

larmyia
Offline
Elder
London
Last seen: 11 years 47 weeks ago
London
Timezone: GMT+1
Joined: 2005-01-25
Posts: 1060
Points: 0

Re: meanwhile, back at the beginner's forum..

samf wrote:

why should I not use the xml declaration when the wc3 page I read showed it there? I'd appreciate knowing.

it forces IE into quirks mode

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 7 years 46 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

For IE (what else).

IE requires a proper doctype to get into standards mode - where it at least tries to behave like a decent browser. For IE the doctype must be the first thing in the html page. Anything before it, like, for example, "<?xml ... " leaves IE in quirks mode.

For XHTML1 the "<?xml ... " is not required unless you are doing something strange with character sets or some other xml only stuff (I think the xhtml spec has the details of when it is required).

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 31 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Samf the xml declaration wasn't expounded on probably due to the fact that every other post has to make mention of it, you have 66 posts to your name I would have assumed that you had seen sight of one of the explanations abound on the forum or perhaps perused the 'How to' section where I think it is mentioned as well, it's a very well known problem. A simple google on 'using xml prolog' will list four entries on the first page dealing with said problem.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Anonymous
Anonymous's picture
Guru

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?

Hugo wrote:
A simple google on 'using xml prolog' will list four entries on the first page dealing with said problem.
Ah, the "Google Crucifix". Wink