I noticed the other day that if a newline is in with the BBCode for the ul or li tags, that the formatting is messed up when it eventually prints on the web page as HTML. Does anyone know of a good way to combat this?PHP Code:function BBCODE($input)
{
/* pattern is an array of patterns
to look for, while replace is an
array of HTML elements to replace
the patterns with.
0 is used for the BOLD tag
1 is used for the ITALIC tag
2 is used for the LINK tag
3 is used for the UNORDERD LIST tag
4 is used for the LIST tag */
$pattern = array();
$pattern[0] = "/\[B\](.*)\[\/[Bb]\]/Ui";
$pattern[1] = "/\[I\](.*)\[\/[Ii]\]/Ui";
$pattern[2] = "/\[URL\=(.*)\](.*)\[\/URL\]/Ui";
$pattern[3] = "/\[UL\](.*)\[\/UL\]/Ui";
$pattern[4] = "/\[LI\](.*)\[\/LI\]/Ui";
$replace = array();
$replace[0] = "<b>$1</b>";
$replace[1] = "<i>$1</i>";
$replace[2] = "<a href=\"http://$1\" target=\"_blank\">$2</a>";
$replace[3] = "<ul>$1</ul>";
$replace[4] = "<li>$1</li>";
$input = preg_replace($pattern, $replace, $input);
$input = str_ireplace('http://http://', 'http://', $input); // used as a precaution since the user might enter the HTTP protocol in the prompt
return $input;
}
**EDIT: Yes, I know that it's case insensitive and needs a little bit of work. I've been meaning to edit the file.


Reply With Quote
I tried matching newlines in testing, but it wasn't working. Now I know I was using the wrong modifier

Bookmarks