Pezmc Posted December 13, 2006 Share Posted December 13, 2006 I have taken this script and improved it from the php tutorials website this is the code atm,[code=php:0]<?phpfunction bbcode_format ($str) { $str = htmlentities($str); $simple_search = array( '/[br]/is', '/[b](.*?)[/b]/is', '/[i](.*?)[/i]/is', '/[u](.*?)[/u]/is', '/[myurl=(.*?)](.*?)[/myurl]/is', '/[url=http://(.*?)](.*?)[/url]/is', '/[align=(left|center|right)](.*?)[/align]/is', '/[img]http://(.*?)[/img]/is', '/[mymail=(.*?)](.*?)[/mymail]/is', '/[mail](.*?)[/mail]/is', '/[font=(.*?)](.*?)[/font]/is', '/[size=(.*?)](.*?)[/size]/is', '/[codearea](.*?)[/codearea]/is', '/[mycode](.*?)[/mycode]/is', '/[p](.*?)[/p]/is' ); $simple_replace = array( //added line break '<br />', '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', // added nofollow to prevent spam '<a href="$1" rel="nofollow" title="$2 - $1">$2</a>', '<a href="$1" rel="nofollow" title="$1">$1</a>', '<div style="text-align: $1;">$2</div>', //added alt attribute for validation '<img src="$1" alt="" />', '<a href="mailto:$1">$2</a>', '<a href="mailto:$1">$1</a>', '<span style="font-family: $1;">$2</span>', '<span style="font-size: $1;">$2</span>', '<span style="color: $1;">$2</span>', //added textarea for code presentation '<textarea class="code_container" rows="30" cols="70">$1</textarea>', //added pre class for code presentation '<pre class="code">$1</pre>', //added paragraph '<p>$1</p>' ); // Do simple BBCode's $str = preg_replace ($simple_search, $simple_replace, $str); // Do <blockquote> BBCode $str = bbcode_quote ($str); $str = str_replace ('<br />','', $str); return $str;}function bbcode_quote ($str) {//added div and class for quotes $open = '<blockquote><div class="quote">'; $close = '</div></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 .= '</div></blockquote>'; } // Do replacement $str = str_replace ('[' . 'quote]', $open, $str); $str = str_replace ('[/' . 'quote]', $close, $str); return $str;}bbcode_format("I aint lame");bbcode_format("Tester [b]bold[/b] [i]ittalic[/i] [u]under[/u]");?>[/code]However this just produces a HUGE error message![code]Warning: preg_replace(): Unknown modifier 'z' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'c' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'y' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'p' in /home/www/shogans.com/new.php on line 47Warning: preg_match_all(): Unknown modifier 'q' in /home/www/shogans.com/new.php on line 64Warning: preg_replace(): Unknown modifier 'b' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier ']' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier ']' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'y' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'r' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'a' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'g' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'y' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'a' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'f' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'z' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'c' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'y' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier 'p' in /home/www/shogans.com/new.php on line 47Warning: preg_match_all(): Unknown modifier 'q' in /home/www/shogans.com/new.php on line 64[/code]I have checked the code and I can't see why this is happening can anyone see????Please help Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 13, 2006 Share Posted December 13, 2006 lotta stuff you have to escape to keep the regex from reading it as a modifier ;) the [ the ] and the / notably....this one gives me no errors, no promise that it WORKS though as I haven't checked for syntax errors, but I've excaped everything I could think of for you, be sure to look it over.. as I said, no promises I got everything...[code=php:0]<?phpfunction bbcode_format ($str) { $str = htmlentities($str); $simple_search = array( '/\[br\]/is', '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[myurl=(.*?)\](.*?)\[\/myurl\]/is', '/\[url=http://http:\/\/(.*?)\](.*?)\[\/url\]/is', '/\[align=(left|center|right)\](.*?)\[\/align\]/is', '/\[img\]http:\/\/(.*?)\[\/img\]/is', '/\[mymail=(.*?)\](.*?)\[\/mymail\]/is', '/\[mail\](.*?)\[\/mail\]/is', '/\[font=(.*?)\](.*?)\[\/font\]/is', '/\[size=(.*?)\](.*?)\[\/size\]/is', '/\[codearea\](.*?)\[\/codearea\]/is', '/\[mycode\](.*?)\[\/mycode\]/is', '/\[p\](.*?)\[\/p\]/is' ); $simple_replace = array( //added line break '<br />', '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', // added nofollow to prevent spam '<a href="$1" rel="nofollow" title="$2 - $1">$2</a>', '<a href="$1" rel="nofollow" title="$1">$1</a>', '<div style="text-align: $1;">$2</div>', //added alt attribute for validation '<img src="$1" alt="" />', '<a href="mailto:$1">$2</a>', '<a href="mailto:$1">$1</a>', '<span style="font-family: $1;">$2</span>', '<span style="font-size: $1;">$2</span>', '<span style="color: $1;">$2</span>', //added textarea for code presentation '<textarea class="code_container" rows="30" cols="70">$1</textarea>', //added pre class for code presentation '<pre class="code">$1</pre>', //added paragraph '<p>$1</p>' ); // Do simple BBCode's $str = preg_replace ($simple_search, $simple_replace, $str); // Do <blockquote> BBCode $str = bbcode_quote ($str); $str = str_replace ('<br />','', $str); return $str;}function bbcode_quote ($str) {//added div and class for quotes $open = '<blockquote><div class="quote">'; $close = '</div></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 .= '</div></blockquote>'; } // Do replacement $str = str_replace ('\[' . 'quote\]', $open, $str); $str = str_replace ('\[\/' . 'quote\]', $close, $str); return $str;}bbcode_format("I aint lame");bbcode_format("Tester [b]bold[/b] [i]ittalic[/i] [u]under[/u]");?>[/code]hopefully that fixes your problem :X Quote Link to comment Share on other sites More sharing options...
Pezmc Posted December 13, 2006 Author Share Posted December 13, 2006 Cool thanks ill just test it Quote Link to comment Share on other sites More sharing options...
Pezmc Posted December 13, 2006 Author Share Posted December 13, 2006 Now I jsut get Warning: preg_replace(): Unknown modifier '/' in /home/www/shogans.com/new.php on line 47Warning: preg_replace(): Unknown modifier '/' in /home/www/shogans.com/new.php on line 47 Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 13, 2006 Share Posted December 13, 2006 I see the problem, challenge yourself and find what it's complaining about ;) first array! Quote Link to comment Share on other sites More sharing options...
Pezmc Posted December 13, 2006 Author Share Posted December 13, 2006 I have never used arrays before but ill give it a try Quote Link to comment Share on other sites More sharing options...
Pezmc Posted December 13, 2006 Author Share Posted December 13, 2006 what do you have to escape out of All [, ], / and "? Quote Link to comment Share on other sites More sharing options...
Pezmc Posted December 13, 2006 Author Share Posted December 13, 2006 Is it the http://? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 13, 2006 Share Posted December 13, 2006 on that one line there is[code=php:0]'/\[url=http://http:\/\/(.*?)\](.*?)\[\/url\]/is',[/code]it should be without that first http://... for some reason the forum keeps adding that http:// Quote Link to comment Share on other sites More sharing options...
Pezmc Posted December 13, 2006 Author Share Posted December 13, 2006 You pasted the same thing ;)But thanks for the help however my script now just diplays a blank page??[code=php:0]<?phpfunction bbcode_format ($str) { $str = htmlentities($str); $simple_search = array( '/\[br\]/is', '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[myurl=(.*?)\](.*?)\[\/myurl\]/is', '/\[url=http://http:\/\/(.*?)\](.*?)\[\/url\]/is', '/\[align=(left|center|right)\](.*?)\[\/align\]/is', '/\[img\]http:\/\/(.*?)\[\/img\]/is', '/\[mymail=(.*?)\](.*?)\[\/mymail\]/is', '/\[mail\](.*?)\[\/mail\]/is', '/\[font=(.*?)\](.*?)\[\/font\]/is', '/\[size=(.*?)\](.*?)\[\/size\]/is', '/\[codearea\](.*?)\[\/codearea\]/is', '/\[mycode\](.*?)\[\/mycode\]/is', '/\[p\](.*?)\[\/p\]/is' ); $simple_replace = array( //added line break '<br />', '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', // added nofollow to prevent spam '<a href="$1" rel="nofollow" title="$2 - $1">$2</a>', '<a href="$1" rel="nofollow" title="$1">$1</a>', '<div style="text-align: $1;">$2</div>', //added alt attribute for validation '<img src="$1" alt="" />', '<a href="mailto:$1">$2</a>', '<a href="mailto:$1">$1</a>', '<span style="font-family: $1;">$2</span>', '<span style="font-size: $1;">$2</span>', '<span style="color: $1;">$2</span>', //added textarea for code presentation '<textarea class="code_container" rows="30" cols="70">$1</textarea>', //added pre class for code presentation '<pre class="code">$1</pre>', //added paragraph '<p>$1</p>' ); // Do simple BBCode's $str = preg_replace ($simple_search, $simple_replace, $str); // Do <blockquote> BBCode $str = bbcode_quote ($str); $str = str_replace ('<br />','', $str); return $str;}function bbcode_quote ($str) {//added div and class for quotes $open = '<blockquote><div class="quote">'; $close = '</div></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 .= '</div></blockquote>'; } // Do replacement $str = str_replace ('\[' . 'quote\]', $open, $str); $str = str_replace ('\[\/' . 'quote\]', $close, $str); return $str;}bbcode_format("I aint lame");bbcode_format("Tester [b]bold[/b] [i]ittalic[/i] [u]under[/u]");?>[/code] Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 13, 2006 Share Posted December 13, 2006 that's because bbcode_format() returns, not echos.try[code=php:0]echo bbcode_format("I aint lame");echo bbcode_format("Tester [b]bold[/b] [i]ittalic[/i] [u]under[/u]");[/code]for the last lines to really see what changes Quote Link to comment Share on other sites More sharing options...
Pezmc Posted December 13, 2006 Author Share Posted December 13, 2006 Sorry i forgot about that i thoughts I had already dealth with it ::).Do you have a website I can link to on my thanks page? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 13, 2006 Share Posted December 13, 2006 nah, it's under indefinite construction, thanks for the offer though. Quote Link to comment Share on other sites More sharing options...
Pezmc Posted December 14, 2006 Author Share Posted December 14, 2006 Is there a easy way to turn it back into bbcode out of html? Quote Link to comment Share on other sites More sharing options...
tarun Posted December 14, 2006 Share Posted December 14, 2006 y not try str_replaceexample[code]<?php$BBCode = array(# Bold'[b]' => '<B>','[/b]' => '</B>',# Italic'[i]' => '<I>','[/i]' => '</I>',# Underline'[u]' => '<U>','[/u]' => '</U>',# Image'[img]' => '<IMG SRC="','[/img]' => '">',# Link'[url=' => '<A HREF="',']' => '">','[/url]' => '</A>',# smilies':)' => '<img src="/images/smilie.gif" />',':(' => '<img src="/images/sad.gif" />'# note the missing comma after the last line above);?><?phpfunction Convert_BBCode( $t ) { $search = array_keys( $GLOBALS['BBCodes'] ); $t = str_replace( $search, $GLOBALS['BBCode'], $t ); return $t;}?><?phpecho .Convert_BBCodes( $text ).;?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.