1BBCode函数function BBCode($Text
  2BBCode函数
  3BBCode函数    // Replace any html brackets with HTML Entities to prevent executing HTML or script 
  4BBCode函数    // Don't use strip_tags here because it breaks [url] search by replacing & with amp 
  5BBCode函数    $Text = str_replace("<", "<", $Text); 
  6BBCode函数    $Text = str_replace(">", ">", $Text); 
  7BBCode函数 
  8BBCode函数 
  9BBCode函数    // Set up the parameters for a URL search string 
 10BBCode函数    $URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'"
 11BBCode函数    // Set up the parameters for a MAIL search string 
 12BBCode函数    $MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@"
 13BBCode函数 
 14BBCode函数    //Non BB URL Search 
 15BBCode函数    //$Text = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" target=\"_blank\" target=\"_new\">\\1://\\2\\3</a>", $Text); 
 16BBCode函数    //$Text = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $Text); 
 17BBCode函数    if (substr($Text, 0, 7== "http://") { 
 18BBCode函数        $Text = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", 
 19BBCode函数            "<a href=\"\\1://\\2\\3\">\\1://\\2\\3</a>", $Text); 
 20BBCode函数        // Convert new line chars to html <br /> tags 
 21BBCode函数        $Text = nl2br($Text); 
 22BBCode函数    } else { 
 23BBCode函数        // Perform URL Search 
 24BBCode函数        $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", 
 25BBCode函数            '<a href="javascript:go(\'$1\',\'new\')">$1</a>', $Text); 
 26BBCode函数        $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", 
 27BBCode函数            '<a href="javascript:go(\'$1\',\'new\')">$2</a>', $Text); 
 28BBCode函数        //$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text); 
 29BBCode函数        // Convert new line chars to html <br /> tags 
 30BBCode函数        $Text = nl2br($Text); 
 31BBCode函数    } 
 32BBCode函数    // Perform MAIL Search 
 33BBCode函数    $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", 
 34BBCode函数        '<a href="mailto:$1">$1</a>', $Text); 
 35BBCode函数    $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", 
 36BBCode函数        '<a href="mailto:$1">$2</a>', $Text); 
 37BBCode函数 
 38BBCode函数    // Check for bold text 
 39BBCode函数    $Text = preg_replace("(\[b\](.+?)\[\/b])is", '<span class="bold">$1</span>', $Text); 
 40BBCode函数 
 41BBCode函数    // Check for Italics text 
 42BBCode函数    $Text = preg_replace("(\[i\](.+?)\[\/i\])is", '<span class="italics">$1</span>', 
 43BBCode函数        $Text); 
 44BBCode函数 
 45BBCode函数    // Check for Underline text 
 46BBCode函数    $Text = preg_replace("(\[u\](.+?)\[\/u\])is", 
 47BBCode函数        '<span class="underline">$1</span>', $Text); 
 48BBCode函数 
 49BBCode函数    // Check for strike-through text 
 50BBCode函数    $Text = preg_replace("(\[s\](.+?)\[\/s\])is", 
 51BBCode函数        '<span class="strikethrough">$1</span>', $Text); 
 52BBCode函数 
 53BBCode函数    // Check for over-line text 
 54BBCode函数    $Text = preg_replace("(\[o\](.+?)\[\/o\])is", '<span class="overline">$1</span>', 
 55BBCode函数        $Text); 
 56BBCode函数 
 57BBCode函数    // Check for colored text 
 58BBCode函数    $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is", "<span style=\"color: $1\">$2</span>", 
 59BBCode函数        $Text); 
 60BBCode函数 
 61BBCode函数    // Check for sized text 
 62BBCode函数    $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is", "<span style=\"font-size: $1px\">$2</span>", 
 63BBCode函数        $Text); 
 64BBCode函数 
 65BBCode函数    // Check for list text 
 66BBCode函数    $Text = preg_replace("/\[list\](.+?)\[\/list\]/is", 
 67BBCode函数        '<ul class="listbullet">$1</ul>', $Text); 
 68BBCode函数    $Text = preg_replace("/\[list=1\](.+?)\[\/list\]/is", 
 69BBCode函数        '<ul class="listdecimal">$1</ul>', $Text); 
 70BBCode函数    $Text = preg_replace("/\[list=i\](.+?)\[\/list\]/s", 
 71BBCode函数        '<ul class="listlowerroman">$1</ul>', $Text); 
 72BBCode函数    $Text = preg_replace("/\[list=I\](.+?)\[\/list\]/s", 
 73BBCode函数        '<ul class="listupperroman">$1</ul>', $Text); 
 74BBCode函数    $Text = preg_replace("/\[list=a\](.+?)\[\/list\]/s", 
 75BBCode函数        '<ul class="listloweralpha">$1</ul>', $Text); 
 76BBCode函数    $Text = preg_replace("/\[list=A\](.+?)\[\/list\]/s", 
 77BBCode函数        '<ul class="listupperalpha">$1</ul>', $Text); 
 78BBCode函数    $Text = str_replace("[*]", "<li>", $Text); 
 79BBCode函数 
 80BBCode函数    // Check for font change text 
 81BBCode函数    $Text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])", "<span style=\"font-family: $1;\">$2</span>", 
 82BBCode函数        $Text); 
 83BBCode函数 
 84BBCode函数    // Declare the format for [code] layout 
 85BBCode函数    $CodeLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"> 
 86BBCode函数                                <tr> 
 87BBCode函数                                    <td class="quotecodeheader"> Code:</td> 
 88BBCode函数                                </tr> 
 89BBCode函数                                <tr> 
 90BBCode函数                                    <td class="codebody">$1</td> 
 91BBCode函数                                </tr> 
 92BBCode函数                           </table>'
 93BBCode函数    // Check for [code] text 
 94BBCode函数    $Text = preg_replace("/\[code\](.+?)\[\/code\]/is", "$CodeLayout", $Text); 
 95BBCode函数 
 96BBCode函数    // Declare the format for [quote] layout 
 97BBCode函数    $QuoteLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"> 
 98BBCode函数                                <tr> 
 99BBCode函数                                    <td class="quotecodeheader"> Quote:</td> 
100BBCode函数                                </tr> 
101BBCode函数                                <tr> 
102BBCode函数                                    <td class="quotebody">$1</td> 
103BBCode函数                                </tr> 
104BBCode函数                           </table>'
105BBCode函数 
106BBCode函数    // Check for [quote] text 
107BBCode函数    $Text = preg_replace("/\[quote\](.+?)\[\/quote\]/is", "$QuoteLayout", $Text); 
108BBCode函数 
109BBCode函数    // Images 
110BBCode函数    // BBCode函数 
111BBCode函数    $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="/$1">', $Text); 
112BBCode函数 
113BBCode函数    // [img=widthxheight]image source[/img] 
114BBCode函数    $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", 
115BBCode函数        '<img src="/$3" height="$2" width="$1">', $Text); 
116BBCode函数 
117BBCode函数    return $Text
118BBCode函数
BBCode CSS
 1}
Then just
PHP Code:
1BBCode函数echo BBCode($string_to_convert); 

相关文章:

  • 2021-07-07
  • 2021-08-18
  • 2021-11-05
  • 2021-11-26
  • 2021-12-20
  • 2022-12-23
  • 2021-04-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-28
  • 2021-08-17
  • 2022-01-07
  • 2022-12-23
  • 2021-12-26
相关资源
相似解决方案