Is this anywhere near something acceptable? I need a function for each HTML tag, and they need to be defined for later use in a Heredoc string. This is my code so far.
<?php
$tags = array (h1, h2, h3, b, i);
foreach ($tags as $key => $value)
{
eval ('function '.$value.' ($str) { return "<'.$value.'>$str</'.$value.'>"; }');
}
This basically takes care of the Heredoc problem concerning functions within heredoc. A quick example:
<<<example
<h1>This is ordinary HTML</h1>
{$h1('This is HTML via. PHP')}
example;
I did all the code over by heart, so please don't be suprised if they contain any errors. I haven't executed the eval-function yet, but it looks alright. Anyway, my question would be: Is this okay, or is it better to go do it the hard-way:
function h1 ($str) { return ...; }
function h2 ($str) { return ...; }
function h3 ($str) { return ...; }
function b ($str) { return ...; }
function i ($str) { return ...; }
And so on ..?