deathadder Posted May 23, 2012 Share Posted May 23, 2012 i am looking to add bbcode to my toplist service for description, i have a working code but it wont allow for example echo $descr; instead os displaying the description it just displays the text descr here is my code <?php function BBCode ($string) { $search = array( '#\[b\](.*?)\[/b\]#', '#\[i\](.*?)\[/i\]#', '#\[u\](.*?)\[/u\]#', '#\[img\](.*?)\[/img\]#', '#\[url=(.*?)\](.*?)\[/url\]#', '#\[code\](.*?)\[/code\]#' ); $replace = array( '<b>\\1</b>', '<i>\\1</i>', '<u>\\1</u>', '<img src="\\1">', '<a href="\\1">\\2</a>', '<code>\\1</code>' ); return preg_replace($search.'si', $replace, $string); } ?> <?php echo BBCode('Here is some [b]Bold![/b] and so on!'); ?> this works perfectly but as soon as i put something along the lines of this echo BBCode('$descr'); it wont display anything but the text $descr Quote Link to comment https://forums.phpfreaks.com/topic/262987-bbcode/ Share on other sites More sharing options...
trq Posted May 23, 2012 Share Posted May 23, 2012 Variables don't need quotes around them and in fact will not interpolate when within single quotes. echo BBCode($descr); Quote Link to comment https://forums.phpfreaks.com/topic/262987-bbcode/#findComment-1347914 Share on other sites More sharing options...
deathadder Posted May 23, 2012 Author Share Posted May 23, 2012 i did try this, but it displayed an error to reprove it ill redo it and screen error update http://prntscr.com/9kzgr the description would be inbetwean those 2 lines normally go to rspsdb.org/serverpage.php?server=PKXILE to see what i mean well it displays it, but it deosent show in bbcode Quote Link to comment https://forums.phpfreaks.com/topic/262987-bbcode/#findComment-1347921 Share on other sites More sharing options...
scootstah Posted May 23, 2012 Share Posted May 23, 2012 It doesn't work because you are trying to concatenate an array which turns it into a string. You need to remove the ".'si'" from preg_replace() and place it after each pattern. Quote Link to comment https://forums.phpfreaks.com/topic/262987-bbcode/#findComment-1347928 Share on other sites More sharing options...
deathadder Posted May 24, 2012 Author Share Posted May 24, 2012 i cant figure out how and were, if i should add any /,. or anything, could you possibley do this for me? Quote Link to comment https://forums.phpfreaks.com/topic/262987-bbcode/#findComment-1348205 Share on other sites More sharing options...
scootstah Posted May 24, 2012 Share Posted May 24, 2012 $search.'si' needs to become $search, and you need to add si at the end of each pattern in the $search array, IE: after the "#" at the end. Quote Link to comment https://forums.phpfreaks.com/topic/262987-bbcode/#findComment-1348283 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.