[RESOLVED] Formatting LIST BBcode
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?
/* 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 = "/\[B\](.*)\[\/[Bb]\]/Ui";
$pattern = "/\[I\](.*)\[\/[Ii]\]/Ui";
$pattern = "/\[URL\=(.*)\](.*)\[\/URL\]/Ui";
$pattern = "/\[UL\](.*)\[\/UL\]/Ui";
$pattern = "/\[LI\](.*)\[\/LI\]/Ui";
$replace = array();
$replace = "<b>$1</b>";
$replace = "<i>$1</i>";
$replace = "<a href=\"http://$1\" target=\"_blank\">$2</a>";
$replace = "<ul>$1</ul>";
$replace = "<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
**EDIT: Yes, I know that it's case insensitive and needs a little bit of work. I've been meaning to edit the file.
Last edited by Joseph Witchard; 01-12-2010 at 10:24 PM.
how is the formatting messed up? does it put it outside a li or ul tag? or is it just outputting ugly? Could you post a screenshot? or a link to a page where we can see it? I'm a visual person that'd help some of us help you.
Only Those Who Listen Prosper
If I'm correctly guessing the issue, add the "s" modifier to the "Ui" modifiers in your patterns, so that the "." wildcard will include newlines.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
That was it. Thanks NogDog I tried matching newlines in testing, but it wasn't working. Now I know I was using the wrong modifier
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)