[eluser]Adam Griffiths[/eluser]
Ok, so I made another version, it's more like yours but you don't need to echo the function.
doctype_pi.php
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
* @return string
*/
function doctype($doctype)
{
$CI =& get_instance();
$CI->config->load('doctypes');
echo $CI->config->item($doctype);
} // doctype
/* End of file doctype_i.php */
/* Location: application/helpers/doctype_pi.php */
config/doctypes.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['xhtml-strict'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
$config['xhtml-transitional'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$config['xhtml-frameset'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
$config['html-strict'] = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
$config['html-transitional'] = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
$config['html-frameset'] = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">\n";
/* End of file doctypes.php */
/* Location: application/config/doctypes.php */
Usage
Code:
<?php doctype('xhtml-strict'); ?>
or
Code:
<?=doctype('xhtml-strict');?>
As before, xHTML and HTML Strict, Tranisitional and Frameset are supported.
Oh and @my error messages, there is no way on earth that they would be shown to the user in the file I gave, it was just a bit of fun. I used it in a project with another developer and it made us both laugh. It was just a quick knockup of a function we needed to have.