Modificherei la funzione e la chiamerei allo stesso modo:
Codice PHP:
<?php
define('TAG_START', '{');
define('TAG_END', '}');
$testo = <<<EOT
<table>
<tr>
<td>PRIMO TESTO a cui segue l'elenco:</td>
<td><a href=file.htm'>[b]Primo punto in elenco[/b]</a></td>
</tr>
{elenco}
<tr>
<td>SECONDO TESTO</td>
</tr>
{elenco}
</table>
EOT;
function AggiungiContenuto($marcatori, $contenitore) {
if(!is_array($marcatori))
$marcatori = array($marcatori);
$ret = $contenitore;
foreach ($marcatori as $marcatore)
if (($pos = strpos($ret, $tagged = TAG_START . $marcatore . TAG_END)) !== false) {
echo substr($ret, 0, $pos);
include $marcatore . '.php';
$ret = substr($ret, $pos + strlen($tagged));
}
return $ret;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ex 1</title>
</head>
<body>
<?php
//chiamata per ogni segnaposto
echo "--------- VERSIONE CON CHIAMATA PER OGNI SEGNAPOSTO ---------";
$testo = AggiungiContenuto('elenco', $testo);
$testo = AggiungiContenuto('elenco', $testo);
echo $testo;
//oppure
echo "--------- VERSIONE CON ARRAY ---------";
$arraySegnaposti = array('elenco','elenco');
echo AggiungiContenuto($arraySegnaposti,$testo);
?>
</body>
</html>
Ho utilizzato due volte elenco, ma puoi dare ai segnaposto i nomi che ti pare.