DrFishNips Posted June 24, 2009 Share Posted June 24, 2009 I added a PHP BBCode parsing script to my site function bbcode($replace) { $bbcode = array( "'\[center\](.*?)\[/center\]'is" => "<center>\\1</center>", "'\[left\](.*?)\[/left\]'is" => "<div style='text-align: left;'>\\1</div>", "'\[right\](.*?)\[/right\]'is" => "<div style='text-align: right;'>\\1</div>", "'\[pre\](.*?)\[/pre\]'is" => "<pre>\\1</pre>", "'\[b\](.*?)\[/b\]'is" => "<b>\\1</b>", "'\[quote\](.*?)\[/quote\]'is" => "<div class='top'><b>Quote:</b><hr>\\1</div>", "'\[i\](.*?)\[/i\]'is" => "<i>\\1</i>", "'\[u\](.*?)\[/u\]'is" => "<u>\\1</u>", "'\[s\](.*?)\[/s\]'is" => "<del>\\1</del>", "'\[move\](.*?)\[/move\]'is" => "<marquee>\\1</marquee>", "'\[url\](.*?)\[/url\]'is" => "<a href='\\1' target='_BLANK'>\\1</a>", "'\[url=(.*?)\](.*?)\[/url\]'is" => "<a href=\"\\1\" target=\"_BLANK\">\\2</a>", "'\[drug=(.*?)\](.*?)\[/drug\]'is" => "<a href=\"?get=drugs&drug=\\1\" target=\"_BLANK\">\\2</a>", "'\[drug_gb=(.*?)\](.*?)\[/drug_gb\]'is" => "<a class=\"gb_link\" href=\"?get=botany&page=preps&prep=\\1\" target=\"_BLANK\">\\2</a>", "'\[prep=(.*?)\](.*?)\[/prep\]'is" => "<a href=\"?get=botany&page=preps&prep=\\1\" target=\"_BLANK\">\\2</a>", "'\[prep_gb=(.*?)\](.*?)\[/prep_gb\]'is" => "<a class=\"gb_link\" href=\"?get=botany&page=preps&prep=\\1\" target=\"_BLANK\">\\2</a>", "'\[mol=(.*?)\]'" => "<img border=\"0\" src=\"chemistry/molecules/\\1-sm.png\">", "'\[3dmol=(.*?)\]'" => "<img border=\"0\" src=\"chemistry/molecules/\\1-sm3d.png\">", "'\[img\](.*?)\[/img\]'is" => "<img border=\"0\" src=\"\\1\">", "'\[img=(.*?)\]'" => "<img border=\"0\" src=\"\\1\">", "'\[email\](.*?)\[/email\]'is" => "<a href='mailto: \\1'>\\1</a>", "'\[size=(.*?)\](.*?)\[/size\]'is" => "<span style='font-size: \\1;'>\\2</span></a>", "'\[font=(.*?)\](.*?)\[/font\]'is" => "<span style='font-family: \\1;'>\\2</span></a>", ); $replace = preg_replace(array_keys($bbcode), array_values($bbcode), $replace); return $replace; } It works well but it doesn't take line breaks into consideration. For example say I enter 2 paragraphs of info into my DB like this Paragraph 1 BLAH BLAH BLAH Paragraph 2 BLAH BLAH BLAH It will be displayed as Paragraph 1 BLAH BLAH BLAHParagraph 2 BLAH BLAH BLAH I can't expect users to manually type in [br] tags or something and all forums obviously handle paragraphs but how do they do it? Link to comment https://forums.phpfreaks.com/topic/163556-bbcode-line-breaks/ Share on other sites More sharing options...
peter_anderson Posted June 24, 2009 Share Posted June 24, 2009 nl2br http://us3.php.net/manual/en/function.nl2br.php Link to comment https://forums.phpfreaks.com/topic/163556-bbcode-line-breaks/#findComment-862903 Share on other sites More sharing options...
DrFishNips Posted June 24, 2009 Author Share Posted June 24, 2009 Thanks alot Link to comment https://forums.phpfreaks.com/topic/163556-bbcode-line-breaks/#findComment-862927 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.