come può sembrare come metodo ? funzionare funziona xD...
codice:
function bbcode_quote ($str) {
//aggiungo classe per quote
$open = '<div class="bbcode-quote">';
$close = '</div>';
//conto i tag di apertura
preg_match_all ('/\[quote\]/i', $str, $matches);
$opentags = count($matches['0']);
//conto i tag di chiusura
preg_match_all ('/\[\/quote\]/i', $str, $matches);
$closetags = count($matches['0']);
//controllo che i tag siano stati chiusi tutti
$unclosed = $opentags - $closetags;
for ($i = 0; $i < $unclosed; $i++) {
$str .= '</div>';
}
//sostituisco bbcode con classe
$str = str_replace ('[' . 'quote]', $open, $str);
$str = str_replace ('[/' . 'quote]', $close, $str);
return $str;
}