PHP problem with XHTML

Please post all new bug reports for Help & Manual 5 here.
Post Reply
User avatar
Martin Wynne
Posts: 2656
Joined: Mon May 12, 2003 3:21 pm
Location: West of the Severn, UK

PHP problem with XHTML

Unread post by Martin Wynne »

If the .php option is selected for topic files, the "Export XHTML 1.1" option needs to be disabled. Otherwise the first line in the file is:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
Most servers are set to allow the shorthand <? delimiter for PHP code in PHP files, so the result is "Parse error on Line 1" and the topic does not display.

The PHP and XHTML options need to be made mutually exclusive.

regards,

Martin.
User avatar
Tim Green
Site Admin
Posts: 23153
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: PHP problem with XHTML

Unread post by Tim Green »

Hi Martin,
The PHP and XHTML options need to be made mutually exclusive.
No, they don't, and it would be counterproductive to switch off XHTML when using PHP. Don't do it. The problem is really in PHP and/or Apache, which are still embarrassingly unable to handle valid tags like this when the server is configured to parse all HTML files as PHP using shorttags.

Really, it would be better to leave out the <?xml.... tag entirely in XHTML because it's now redundant and unnecessary. Unfortunately, this would probably break a lot of help projects because when this tag is there it switches IE6 and some other old browsers into quirks mode, and suddenly leaving it out could bork the layout. There is a simple solution: In projects targeting a server where all HTML files are parsed as PHP and shorttags are enabled, replace the <%DOCTYPE%> variable with this:

Code: Select all

<?php echo('<?xml version="1.0" encoding="utf-8"?>'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Actually, it is even better to use the new "skinny" doctype, which will now work everywhere:

Code: Select all

<?php echo('<?xml version="1.0" encoding="utf-8"?>'); ?>
<!DOCTYPE html>
Regards,
Tim (EC Software Documentation & User Support)

Private support:
Please do not email or PM me with private support requests -- post to the forum directly.
User avatar
Martin Wynne
Posts: 2656
Joined: Mon May 12, 2003 3:21 pm
Location: West of the Severn, UK

Re: PHP problem with XHTML

Unread post by Martin Wynne »

Tim Green wrote:Actually, it is even better to use the new "skinny" doctype, which will now work everywhere:

Code: Select all

<?php echo('<?xml version="1.0" encoding="utf-8"?>'); ?>
<!DOCTYPE html>
Hi Tim,

Many thanks for that nifty trick. :)

I don't understand why the shorthand tags were ever introduced. How much more trouble is it to use the proper tag? :?

regards,

Martin.
Post Reply