SyncViews Posted April 15, 2008 Share Posted April 15, 2008 Ok it's addin quotes this time. I was going to do it the same way as the other bb codes (see parse_part) but the problem is it then won't work with say this because the quote tags are nolonger in the same string so won't be matched... [quote] [code] some quoted code [/code] [/quote] but if I prase it before spliting then this wouldn't work instead [code] [quote] this is what quote tags look like [/quote] [/code] I really have no idea how to do it so both the above examples work... <?php function parse($str) { $parts = preg_split('#(\[/?code\])#i', $str, -1, PREG_SPLIT_DELIM_CAPTURE); // every fourth index will contain content to be parsed (starting at 0) foreach ($parts as $i => $part) { switch($i % 4) { case 0: $parts[$i] = parse_part($part); break; case 1: $parts[$i] = '<div class="bb_code_outer"><span class="bb_code_title">CODE:</span><pre class="bb_code">'; break;//code header case 2: $parts[$i] = htmlentities($part, ENT_QUOTES); break; case 3: $parts[$i] = '</pre></div>'; break;//code footer } } return join('', $parts); } function parse_part($str) { $str = htmlentities($str, ENT_QUOTES); //add new lines $str = str_replace("\n","<br />\n",$str); //smilies $smilie_root = $url_root.'/smilies/'; $str = str_replace('','<img scr="'.$smilie_root.'smile.png" alt="smile" title="smile" />',$str); $str = str_replace('','<img scr="'.$smilie_root.'sad.png" alt="sad" title="sad" />',$str); $str = str_replace('','<img scr="'.$smilie_root.'biggrin.png" alt="biggrin" title="biggrin" />',$str); $str = str_replace('','<img scr="'.$smilie_root.'tongue.png" alt="tongue" title="tongue" />',$str); //bb codes $bb_codes = array( '/\[b\](.*?)\[\/b\]/is', //BOLD '/\[i\](.*?)\[\/i\]/is', //ITALIC '/\[u\](.*?)\[\/u\]/is', //UNDERLINE '/\[url\](.*?)\[\/url\]/is', //URL '/\[url\=(.*?)\](.*?)\[\/url\]/is', //URL2 '/\[img\](.*?)\[\/img\]/is', //IMAGE '/\[mail\](.*?)\[\/img\]/is', //MAIL '/\[mail\=(.*?)\](.*?)\[\/mail\]/is', //MAIL2 '/\[colo?r\=(.*?)\](.*?)\[\/colo?r\]/is', //COLOUR '/\[size\=(.*?)\](.*?)\[\/size\]/is', //SIZE '/\[font\=(.*?)\](.*?)\[\/font\]/is', //FONT '/\[align\=(left|center|right)\](.*?)\[\/align\]/is', //ALIGN '/\[pre\](.*?)\[\/pre\]/is' //PREFORMATTED ); $bb_html = array( '<span style="font-weight: bold">$1</span>', //BOLD '<span style="font-style: italic">$1</span>', //ITALIC '<span style="text-decoration: underline">$1</span>', //UNDERLINE '<a href="$1">$1</a>', //URL '<a href="$1">$2</a>', //URL2 '<img src="$1" alt="$1" />', //IMAGE '<a href="mailto:$1">$1</a>', //MAIL '<a href="mailto:$1">$2</a>', //MAIL2 '<span style="color: $1">$2</span>', //COLOUR '<span style="font-size: $1">$2</span>', //SIZE '<span style="font-family: $1">$2</span>', //FONT '<span style="text-align: $1">$2</span>', //ALIGN '<pre>$1</pre>' //PREFORMATTED ); $str = preg_replace ($bb_codes, $bb_html, $str); return $str; } ?> Link to comment https://forums.phpfreaks.com/topic/101279-more-bb-problems/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.