www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Formatting LIST BBcode

  1. #1
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063

    resolved [RESOLVED] Formatting LIST BBcode

    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;
        
        } 
    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?

    **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 11:24 PM.

  2. #2
    Join Date
    Oct 2003
    Posts
    379
    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.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    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

    eBookworm.us

  4. #4
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles