I’m looking for a better way to generate dynamic html from php.
Before I would do something like this:
//generate.php
for(...)
{
$markup .= '<a id="'.$i.'">link'.$i.'</a>';
}
This is really ugly, and I would much prefer not to have to define my markup inline in php strings.
I am looking for the functionality of include "markup.php";, but I need to be able to store the result into a string, and not output it right away. Something like below would be excellent.
//generate.php
for(...)
{
$markup .= include "markup.php";
}
//markup.php
<a id="<?=$i?>">link<?=$i?></a>
Use a templating engine such as Smarty TPL. This is what they are.
They both separate the HTML display from the logic and provide convenience functions to generate tedious things like HTML radio buttons.