Jump to content

Basic HTML Tag Class


davestewart

Recommended Posts

As part of a class I'm using to build tables, I've created a general Element class that holds a few properties and methods to output the essential bits of HTML tags, with an easy to use API:

 

// properties
    $tag
    $content
    $class
    $style
    $attributes

// constructor
    __construct($content = '', $class = '', $style = '', $attributes = '')

// getters
    html() // wraps the following methods:
    open()
    content()
    close()

 

It's about 50 lines of PHP. It could obviously be sub-classed for things like self closing tags, or specific tag types.

 

My question is, does anyone know if native PHP simple XML would offer faster performance than my nice, simple, lean class? A typical table might hold 20 rows of 6 columns, so 120 or so operations.

 

All my classes are also loaded in the same file.

 

Cheers,

Dave

Link to comment
https://forums.phpfreaks.com/topic/166169-basic-html-tag-class/
Share on other sites

To create a test case you must make sure that what you test is in both cases the same.

 

$mt = microtime(true);
..test internal..
$rt = microtime(true) - $mt;//time the test needed to run

$mt = microtime(true);
..test yours..
$rt = microtime(true) - $mt;

 

All my classes are also loaded in the same file.

 

Is not so good if you only need a few.

Link to comment
https://forums.phpfreaks.com/topic/166169-basic-html-tag-class/#findComment-876374
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.