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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.