Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Php/xhtml Pages, A simple guide to making valid PHP/XHTML pages
FirefoxRocks
post Oct 28 2006, 07:27 PM
Post #1


Super Member
Group Icon

Group: [HOSTED]
Posts: 696
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



As you know, if you use the XML encoding tag, XHTML Doctype and the XML Namespace attribute in the html tag on a .php document, it won't render properly and will infact display errors.

A solution to this problem is to use the require function of the PHP system.

(I'm new at PHP, just learnt it yesterday, please feel free to correct anything smile.gif)

Here are some examples of pre-body text:

Normal XHTML document pre-body information:
CODE
[b]<?xml version='1.0' encoding='iso-8859-1'?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>[/b]
<head>
<title>My XHTML Site</title>
<link rel="stylesheet" href="allpages.css" type="text/css" />
<style type="text/css">
...style information here...
</style>
</head>


Normal HTML 4.01 document pre-body information:
CODE
[b]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">[/b]
<html>
<head>
<title>My HTML Site</title>
<link rel="stylesheet" href="allpages.css" type="text/css" />
<style type="text/css">
...style information here...
</style>
</head>


Note: there are also many doctypes for HTML and XHTML, these are just some examples. There is also HTML 3.2 and 2.0 instead of 4.01.

PHP document:
CODE
<html>
<head>
<title>My PHP Site</title>
</head>


Here is the one you should be using for PHP/XHTML pages:
CODE
<?php require("doctype.php"); ?>
<head>
<title>Achoo!</title>
<link rel="stylesheet" href="allpages.css" type="text/css" />
<style type="text/css">
...style information here...
</style>
</head>


The doctype.php file:
CODE
<?php
$xml="<?xml version='1.0' encoding='iso-8859-1'?>";
$doctype="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>";
$html="<html xmlns='http://www.w3.org/1999/xhtml'>";

echo $xml . " " . $doctype . " " . $html;
?>


In this case, the browser still outputs the XML encoding, the DOCTYPE declaration and the HTML document declaration. If you view the source of the page, you can't tell that it used the PHP (remember, PHP is server-side).

I hope this has helped you create more valid pages for your website. Please remember, we are cleaning up the web here, so make sure your documents have valid XHTML/CSS and no broken links. smile.gif
Go to the top of the page
 
+Quote Post
FirefoxRocks
post Feb 6 2007, 12:13 AM
Post #2


Super Member
Group Icon

Group: [HOSTED]
Posts: 696
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



I already use that. Is there anyway you can make the XML processing instruction, DOCTYPE and HTML appear on separate lines in the View Source in the browser?

The <head> element may be also added into the script, as it ALWAYS comes right after <html xmlns:"http://www.w3.org/1999/xhtml">.

I do also use another script to support XHTML even further. I'll put that in another post though.
Go to the top of the page
 
+Quote Post
jlhaslip
post Feb 6 2007, 02:44 AM
Post #3


Advanced Member
Group Icon

Group: Members
Posts: 187
Joined: 15-November 05
From: Inland from the Left Coast of Canada
Member No.: 9,627



CODE

<?xml version='1.0' encoding='iso-8859-1'?>

Having this in the first line of the document forces Internet Explorer into "quirks" mode and the page rendering is unpredictable, so I would drop that line from the document. The page will still validate without the xml version line on the page. It is a glitch in IE 6 and IE7. (surprise!!!)
Go to the top of the page
 
+Quote Post
FirefoxRocks
post Feb 6 2007, 11:01 PM
Post #4


Super Member
Group Icon

Group: [HOSTED]
Posts: 696
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



I know, just found that out sometime this week.
I will be making a further tutorial that support HTTP_ACCEPT values for the header and ejecting out the correct output with XML processing line, DOCTYPE and also the HTML tag. The MIME type "application/xhtml+xml" will also be used if a Mozilla-derivative browser or Opera is being used. IE will use "text/html" and no XML encoding to avoid quirks mode.

I will need to add some text of my own into the new tutorial because I do not want to plagiarize.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Upgrading Your Site!(0)
  2. Custom Error Pages(4)
  3. Xhtml Tutorial - Introduction(0)
  4. Juggling An Iframe Box With Xhtml Sites(8)
  5. Php Tutorial: Making A Shoutbox(11)


 



- Lo-Fi Version Time is now: 11th October 2008 - 05:03 AM