Nov 23, 2009

Php/xhtml Pages - A simple guide to making valid PHP/XHTML pages

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Websites and Web Designing

Php/xhtml Pages - A simple guide to making valid PHP/XHTML pages

FirefoxRocks
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

 

 

 


Comment/Reply (w/o sign-up)

FirefoxRocks
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.

Comment/Reply (w/o sign-up)

jlhaslip
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!!!)

Comment/Reply (w/o sign-up)

FirefoxRocks
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.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : php, xhtml, pages, simple, guide, making, valid, php, xhtml, pages

  1. Php Tutorial: Making A Shoutbox
    Requirements: PHP, MySQL (14)
  2. Juggling An Iframe Box With Xhtml Sites
    How to make it strict and valid (11)
    You most likely have encountered a situation (as a web developer) where you have an iframe box and
    you are using valid XHTML Strict. Iframes are still valid in FRAMESET and TRANSITIONAL XHTML but it
    is best to use XHTML 1.0 Strict or XHTML 1.1 (application/xhtml-xml). A method for including iframes
    have been found. It doesn't use the tag at all. Since tags are depreciated, new tags/CSS are
    to replace them (except DOM, which is a little off topic here). The and tags were replaced by
    . Yes, is for inserting any foreign object into XHTML documents. Since I....
  3. Custom Error Pages
    Very simple error pages without php or java (4)
    Creating a custom error page without PHP You can easily create your own custom error pages by
    making an .htaccess file QUOTE The .htaccess file is a simple text file which can do many
    things on your website. You can use it for several different things: custom error pages, banning
    people from your site, password protecting your directories and automatic redirects to another page
    among others. Not every web host will allow you to use an .htaccess file. Usually, if your server
    runs Unix or Linux, or any version of the Apache web server it will support .htaccess. If....
  4. Making A Website
    Along with Some Dos & Don'ts (2)
    I had originally had this posted on my domain at nevernormal.com, and thought that you guys could
    use it here as well. Granted, this is geared to the uber newbie, so don't razz me if I
    don't suggest the most advanced in web design. lol QUOTE So, you want to make a
    website? 1. First, think about what you want your site to be about. There are fanfic sites, like
    Drastic Measures and fanfiction.net ; cliques or clubs, like the BtVS Writers' Guild ; or, if
    you want, you could have a general site, whether it be about a show/movie you like, or even j....
  5. Custom Error Pages With .htaccess
    (11)
    So, who wants a site where instead of getting a default "Error 404" page in that ghastly font
    (Times) when you type the wrong address, you get a beautiful "Error 404" page that fits with your
    site's layout, colour and font scheme? Well, if you do, I'm going to show you how to do it
    with .htaccess. --- The most commonly occuring error pages are: 400 Bad Request 401
    Authorization Required 403 Forbidden 404 Page Not Found 500 Internal Server Error 503 Service
    Unavailable Open up a new file in your favourite text editor. Enter this: CODE ErrorDocument ....

    1. Looking for php, xhtml, pages, simple, guide, making, valid, php, xhtml, pages

See Also,

*SIMILAR VIDEOS*
Searching Video's for php, xhtml, pages, simple, guide, making, valid, php, xhtml, pages
advertisement



Php/xhtml Pages - A simple guide to making valid PHP/XHTML pages

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com