lo so hai ragione , non si capisce niente , adesso lo sistemo cosi' è piu' chiaro
function count_t($tag, $text)
{
$count = 0; for($i=0;
$i<=strlen($text) - strlen($tag);$i++)
{
$s = substr($text, $i, strlen($tag));
if($s == $tag) $count++;
}
return $count;
}
$tag = array( ";", ";" /* tag_aperto;tag_chiuso */ );
$my_text = "Il testo [b]è in grassetto"; foreach($tag as $t)
{
$g = explode(";", $t);
$diff = count_t($g[0], $my_text) - count_t($g[1], $my_text);
if($diff >= 1)
{
for($j = 0; $j < $diff;$j++) $my_text .= $g[1];
}
}
echo $my_text;
}