Welcome Guest, Not a member yet? Register   Sign In
Doctype Plugin
#1

[eluser]Adam Griffiths[/eluser]
I recently made this plugin to display a doctype easily. This should be saved as doctype_pi.php in your application/plugins/ folder and loaded like...

Code:
$this->load->plugin('doctype');

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Doctype
*
* Generates a doctype based on the strings passed to the function.
* Defaults to xHTML Strict
*
* @access    public
* @param    string
* @param    string
* @return    string
*/

function doctype($lang = 'xhtml', $type = 'strict')
{    
    if($lang === NULL)
    {
        exit("No language sent to HTML Helper doctype()");
    }
    elseif($lang === 'xhtml')
    {
        if($type === 'strict')
        {
            echo("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
        }
        elseif($type === 'transitional')
        {
            echo("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
        }
        elseif($type = 'frameset')
        {
            echo("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n");
        }
        else
        {
            show_error("Never be seen. Sshhhhhhh!");
        }
    }
    elseif($lang === 'html')
    {
        if($type === 'strict')
        {
            echo("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n");
        }
        elseif($type === 'transitional')
        {
            echo("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
        }
        elseif($type = 'frameset')
        {
            echo("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">\n");
        }
        else
        {
            show_error("Never be seen. Sshhhhhhh!");
        }
    }
    else
    {
        show_error("Never be seen. Sshhhhhhh!");
    }
    
} // doctype

/* End of file doctype_pi.php */
/* Location: application/helpers/doctype_pi.php */

Usage
You can display both HTML and xHTML doctpyes using this funtion. Pass the HTML type to the first function, and the doctype you want to use (strict, transitional, frameset).

The default will be xHTML Strict.

It's small, but it sure does help me a lot! It's easier to type out doctype(); than <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">.

It's probably not the best I could've done, I could've done it differently. But it works and is quite useful to myself, so I thought I'd share.

Thanks.


Messages In This Thread
Doctype Plugin - by El Forum - 09-02-2008, 02:45 PM
Doctype Plugin - by El Forum - 09-02-2008, 03:19 PM
Doctype Plugin - by El Forum - 09-02-2008, 03:36 PM
Doctype Plugin - by El Forum - 09-03-2008, 02:28 AM
Doctype Plugin - by El Forum - 09-03-2008, 03:14 AM
Doctype Plugin - by El Forum - 09-03-2008, 03:42 AM
Doctype Plugin - by El Forum - 09-03-2008, 04:02 AM
Doctype Plugin - by El Forum - 09-13-2008, 04:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB