xHTML-o-MATIC
A mini framework for handling PHP web frontends.
Loading...
Searching...
No Matches
xHTML-o-MATIC

[License](LICENSE) Language Docs

A small, object-oriented PHP library that provides a DOM-like API to build, manage and render xHTML pages programmatically. The library helps separate presentation structure from application logic by exposing HTML elements as PHP objects that can be composed, nested and rendered as compliant xHTML.

Highlights

  • Lightweight OO approach to generate xHTML programmatically
  • DOM-like tree model with element classes for common HTML tags
  • Helpers for tables, unparsed blocks and structured content insertion
  • Output is intended to be valid xHTML (e.g., xHTML 1.0 Transitional)

When to use

  • You want clear separation between HTML structure and PHP logic
  • You prefer building pages by composing elements instead of echoing HTML strings
  • You need programmatic helpers for tables, fragments and unparsed HTML

Quick Start

  1. Include the library (use the src folder or place files in your include path).
require_once 'src/xHTML_All.php';

Usage Example

The following example is preserved from the original repository and demonstrates basic usage and features.

<?php
/*******************************************************************/
/* As it can be seen here, it is very easy to split basic */
/* structure (that can be placed in your class constructor) */
/* from page's content, that can be dynamically placed in your */
/* member functions or similar. */
/* Of course, its output is 100% xHTML 1.0 Transitional Valid */
/*******************************************************************/
require_once '/xHTML_All.php';
$webPage=new xHTML_Page("My testing page");
$webPage->AddCSSFile("some-css-file.css");
$header=new xHTML_Div();
$header->SetID("header");
$footer=new xHTML_Div();
$footer->SetID("footer");
$contentMainDiv=new xHTML_Div();
$contentMainDiv->SetID("content");
$webPage->AddContent($header);
$webPage->AddContent($footer);
$footer->AddContentBefore($contentMainDiv); //Demonstration of inserting before an already existing element
$contentMainDiv->AddContent(new xHTML_P("Welcome to the xHTML-o-MATIC test page!")); //Demonstration of dynamic content adition when structure have already been stablished
$contentMainDiv->AddContent(new xHTML_UnparsedCode("<p>And also, it allows to add unparsed code by hand like this <a href='http://www.google.es'>google link</a> inside a p element</p>"));
$table=new xHTML_Table();
$table->SetProperty("align", "center"); //Property set demonstration
$table->SetProperty("border", "1");
$table->SetProperty("width", "60%");
$table->AddContentMatrix(0, 0, new xHTML_P("This is cell 0,0"));
$table->AddContentMatrix(0, 1, new xHTML_P("This is cell 0,1"));
$table->AddContentMatrix(1, 1, "This is cell 1,1"); //No p item, just text, and item 1,0 left empty with no problems
$table->SetCellProperty(1, 1, "align", "right"); //Demonstration for an easy cell property set inside its matrix
$webPage->AddContent($table);
$webPage->Render(); //Renders (outputs) the whole configured page
?>
Definition xHTML_Div.php:12
Definition xHTML_P.php:13
Definition xHTML_Page.php:12
Definition xHTML_Table.php:12
Definition xHTML_UnparsedCode.php:12

Available classes

  • Core include: src/xHTML_All.php to require all element classes
  • Element classes included in the library (found in src/):
    • W3COKButton.php
    • xHTML_A.php
    • xHTML_BR.php
    • xHTML_Base.php
    • xHTML_Body.php
    • xHTML_Comment.php
    • xHTML_Div.php
    • xHTML_Exceptions.php
    • xHTML_Form.php
    • xHTML_Generic.php
    • xHTML_H.php
    • xHTML_Head.php
    • xHTML_Img.php
    • xHTML_Link.php
    • xHTML_List.php
    • xHTML_P.php
    • xHTML_Page.php
    • xHTML_Script.php
    • xHTML_Span.php
    • xHTML_Style.php
    • xHTML_Table.php
    • xHTML_Text.php
    • xHTML_UnparsedCode.php

Documentation

  • Full generated documentation is available in the docs/ folder. Open docs/index.html in a browser to browse the API and examples.

Installation and integration

  • There is no installer; copy the src/ folder into your project and ‘require_once 'src/xHTML_All.php’` from your bootstrap or script.
  • The library is plain PHP and has no external dependencies.

Contributing

  • Contributions are welcome. Please open issues or pull requests with clear descriptions and tests where appropriate.

License

  • This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.

Support

  • For questions or issues, please open an issue in the repository.