Ciao,
ciao sto scrivendo un bbcode per un forum, e sono arrivato qui:
codice:<?php function bbcode_format ($str) { $str = htmlentities($str); $simple_search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[align\=(left|center|right)\](.*?)\[\/align\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[mail\=(.*?)\](.*?)\[\/mail\]/is', '/\[mail\](.*?)\[\/mail\]/is', '/\[font\=(.*?)\](.*?)\[\/font\]/is', '/\[size\=(.*?)\](.*?)\[\/size\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', ); $simple_replace = array( '$1', '$1', '<u>$1</u>', '$2', '$1', '<div style="text-align: $1;">$2</div>', '[img]$1[/img]', '$2', '$1', '<span style="font-family: $1;">$2</span>', '<span style="font-size: $1;">$2</span>', '<span style="color: $1;">$2</span>', ); // Do simple BBCode's $str = preg_replace ($simple_search, $simple_replace, $str); // Do <blockquote> BBCode $str = bbcode_quote ($str); return $str; } function bbcode_quote ($str) { $open = '<blockquote>'; $close = '</blockquote>'; // How often is the open tag? preg_match_all ('/\[quote\]/i', $str, $matches); $opentags = count($matches['0']); // How often is the close tag? preg_match_all ('/\[\/quote\]/i', $str, $matches); $closetags = count($matches['0']); // Check how many tags have been unclosed // And add the unclosing tag at the end of the message $unclosed = $opentags - $closetags; for ($i = 0; $i < $unclosed; $i++) { $str .= '</blockquote>'; } // Do replacement $str = str_replace ('[' . 'quote]', $open, $str); $str = str_replace ('[/' . 'quote]', $close, $str); return $str; } ?>
vorrei implementarlo con la possibbilità di inserire il comendo code per postare il codice e vorrei che al testo mi riconoscesse gli accapo e i link nel caso non li inserisco tramite bbcode....
potreste aiutarmi completando il codice??


Rispondi quotando
