-4

I want to make a custom BBCode for my forum site, but I've run into an issue, and I'm having a hard time fixing it.

This is what's in the database for the body of the thread "[b]Bold[/b][i]Italic[/i][strike]Strike[/strike]".

However the output is displayed like this "[i]Italic[/i][strike]Strike[/strike]".

So, I'm guessing it's an issue with echoing it out, but i'm not sure how to fix it. Here's the current code:

function bbcode($input) {
    $input = strip_tags($input);
    $input = htmlentities($input);

    $search = array('/\[b\](.*?)\[\/b\]/is');

    $replace = array('<b>$body</b>');

    return preg_replace($search, $preg_replace, $input);
}

while($row = mysql_fetch_array($threadquery, MYSQL_ASSOC)) {
    $body = str_replace("\n",'<br>', $row['body']);
}

echo bbcode($body);
UnderMyWheel
  • 241
  • 2
  • 11
  • Why not save yourself the trouble and use one which has been tested and trusted? I'd suggest using [Parsedown](http://parsedown.org/). – Script47 Dec 31 '15 at 19:58
  • bbcode is a little dated, just embed a editor like cke editor: http://ckeditor.com/ –  Dec 31 '15 at 19:59
  • @Anthony Please try my library for parsing shortcodes and BBCodes: github.com/thunderer/Shortcode . If you need more information, submit an issue and I'll help. – Tomasz Kowalczyk Jan 27 '16 at 19:29

1 Answers1

0

proper code should be:

$replace = array('<b>$1</b>');

return preg_replace($search, $replace, $input);
Iłya Bursov
  • 23,342
  • 4
  • 33
  • 57