While I was unavailable to access the forum, I have learned the new leve of tagging. Tag elements are created using PHP classes. You need to have PHP 5.* installed on your web server.
Example:
Code:
<html>
<head>
<title>Generating X(HT)ML elements with PHP classes</title>
</head>
<body>
<?php
require 'HTMLParagraph.class.php';
require 'HTMLDiv.class.php';
require 'HTMLH1.class.php';
require 'HTML.class.php';
echo HTML::p('This is a static method!');
echo HTML::div(HTML::h1('Welcome to my web site!'), array('id' => 'header'));
?>
</body>
</html>
It produces this (if you can not see the page, I am working on it) page:
Generating X(HT)ML elements with PHP classes
with this source:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Generating X(HT)ML elements with PHP classes</title>
</head>
<body>
<p>This is a static method!</p>
<div id="header"><h1>Welcome to my web site!</h1></div>
</body>
</html>
Code for: HTML.class.php
Code:
<?php
require_once 'HTMLParagraph.class.php';
require_once 'HTMLH1.class.php';
require_once 'HTMLDiv.class.php';class HTML
{
public static function p($content, $attributes = array()) {
return new HTMLParagraph($content, $attributes);
}
public static function h1($content, $attributes = array()) {
return new HTMLH1($content, $attributes);
}
public static function div($content, $attributes = array()) {
return new HTMLDiv($content, $attributes);
}
}
?>
Code for: HTMLDiv.class.php
Code:
<?php
require_once 'HTMLElement.class.php';class HTMLDiv extends HTMLElement
{
protected $tagname = 'div';
public function __construct($content, $attributes = array())
{
parent::__construct($content, $attributes);
}
}?>
with code for HTMLElement.class.php:
Code:
<?php
class HTMLElement
{
protected $content;
protected $tagname;
protected $attributes;
public function __construct($content, $attributes = array())
{
$this->content = $content;
$this->attributes = $attributes;
}
public function getSource()
{
return '<' . $this->tagname . $this->getAttributeSource() . '>' .
$this->content .
'</' . $this->tagname . '>';
}
public function getAttributeSource()
{
$attributes = '';
if (count($this->attributes)) {
foreach ($this->attributes as $attrnme => $attrval)
{
$attributes .= ' ' . $attrnme . '="' . $attrval . '"';
}
}
return $attributes;
}
public function __toString()
{
return $this->getSource();
}
}?>
So what is the clue? Don't you see the advantages?
- This is on a more general level than a CMS. See point 4 and 6 below.
- Coding is reduced to writing text once the API is in place.
- Less errors.
- Tag content and attributes can be pulled from a database.
- You can make a class for each static (X)HTML element.
- The API can of course be used to make dynamic XML elements.
Remember:
Imagination is more important than knowledge.
Exercise:
Write the class for HTMLParagrap and HTMLH1 and you get it.
Combine this with AJAX and JavaScript ...
Combine this with Microformats SEO and the Sumo parser.
and
SEO:: Science, art or metaphysics?
"bad markup should be reduced to bad programming". At least badly nested and unclosed tags should no longer be a problem once the API is made. X(HT)ML elements are produced automatically like:
Code:
echo HTML::div(HTML::h1('Welcome to my web site!'), array('id' => 'header'));
where the text in read is variable and can be pulled from external sources like another website (RssFeed) or a database.
Inspiration:
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - SitePoint Books