Trying to come up with a basic way to display code in a way that would be nicely maintainable, I thought of doing something like this:
echo htmlfunction('a',array('href'=>'http://google.com'),'google');
to generate:
<a href="http://google.com">google</a>
this would use as a global scale function to output all html tags. that way, if I ever wanted to change the way my html is displayed, I could easily do it with one tweak.
does using this kind of outputting mean a grave loss of agility in performance?
thanks.
No, but you would be reinventing the wheel and in a wrong way.
Instead of writing
echo title("bar");to echo<title>bar</title>, use a templating engine to output your dynamic data inside a static HTML template, that looks like<title>$title</title>where your code has$template->assign('title','bar');.That way you will be keeping markup as markup and code as code and in separate files, which is a worthy goal in at least the maintainability and flexibility departments.
Look, for example, at Smarty