Menu

Basic Usage

Basic Usage

Initialize

First, you need to include the library, we assume that you copied it inside the /libs directory, we need to create a constant WEB_LIBS libs/

define('WEB_LIBS', 'libs/');
include_once WEB_LIBS ."xhtml.php";

Then you can create a new web page on this way:

$page = new xhtml('My example Website');
xhtml: Creates a new page skeleton

object xhtml (string $title [, string $charset='UTF-8'][, string $language='en-US'])

Doing this you have a basic web site created, also some properties are already set, head and a body are ready.
by default this properties are set:
language = en-US (set the meta Content-Language)
charset = UTF-8 (set the meta Content-Type)
rating = general
robots = all

Other special properties you can set are:
date
description
author
publisher

Lets set some properties:

$page->description = "This is a example website";
$page->author = 'MeduZaPaT';
$page->publisher = 'Someone else';

Or you can create your own (all are meta tags) but you only can use for the property name one word starting with a letters and numbers and '_', but without spaces or any special character.

$page->variable = "some value"; /* works */
$page->wrong-variable = "error"; /* WRONG can not use - */
$page->last_update = '10:10pm'; /* works */
$page->developer = 'Some other guy'; /* works */

If you need to create properties with special characters or spaces in the name you need to add meta tags
that will be explained on the next section [Add Tags].

Special Settings

compress_output: this function activates the output compression

compress_output ([bool $value = true*])

So lets deactivate the compression, by default is on, this can be set at any time, because is only used with the page render at the end of the program

$page->compress_output(false);

Examples

Lets put all together and check the result:

<?php
define('WEB_LIBS', 'libs/');
include_once WEB_LIBS ."xhtml.php";
$page = new xhtml('My example Website');
$page->description = 'This is a example website';
$page->author = 'MeduZaPaT';
$page->publisher = 'Someone else';
$page->variable = 'some value';
$page->last_update = '10:10pm';
$page->developer = 'Some other guy';
$page->compress_output(false);
?>

The result is:

~~~~~~
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<title>My example Website</title>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<meta content="en-US" http-equiv="Content-Language">
<meta content="This is a example website" name="description">
<meta content="MeduZaPaT" name="author">
<meta content="Someone else" name="publisher">
<meta content="general" name="rating">
<meta content="all" name="robots">
<meta content="some value" name="variable">
<meta content="10:10pm" name="last_update">
<meta content="Some other guy" name="developer">




~~~~~~~~

As you can see we have a perfect valid xHTML code here

Note: if we activate the compression the result will be the same but with no end-lines

Important Notes

The xhtml object do not write to the buffer until the program ends or the object is unset, any output will appear before <!DOCTYPE.
After you created the object you can keep sending html headers, setting cookies or initialize sessions
The object will keep control of the xhml code and will ignore any incorrect tag with a notice error, also will inform of required attributes on tags that need them

Next chapter: how to add content


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.