CyClon
Newbie | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору Выкладываю просто функцию, правильную скажем: Код: <?php function bb_to_html($content) { // Переносы строк $content = str_replace("\n", "<br />", $content); // Жирный, Курсив (Наклонный), Подчеркнутый, Перечеркнутый $content = preg_replace("/\[B\](.+?)\[\/B\]/", "<b>\\1</b>", $content); $content = preg_replace("/\[I\](.+?)\[\/I\]/", "<i>\\1</i>", $content); $content = preg_replace("/\[U\](.+?)\[\/U\]/", "<u>\\1</u>", $content); $content = preg_replace("/\[S\](.+?)\[\/S\]/", "<s>\\1</s>", $content); // Размер шрифта $content = preg_replace("/\[SIZE=(.+?)\](.+?)\[\/SIZE\]/", "<font size=\"\\1\">\\2</font>", $content); // Цвет шрифта $content = preg_replace("/\[COLOR=(.+?)\](.+?)\[\/COLOR\]/", "<font color=\"\\1\">\\2</font>", $content); // Выравнивание (По левому краю, По центру, По правому краю) $content = preg_replace("/\[LEFT\](.+?)\[\/LEFT\]/", "<div align=\"left\">\\1</div>", $content); $content = preg_replace("/\[CENTER\](.+?)\[\/CENTER\]/", "<div align=\"center\">\\1</div>", $content); $content = preg_replace("/\[RIGHT\](.+?)\[\/RIGHT\]/", "<div align=\"right\">\\1</div>", $content); // Вставить изображение $content = preg_replace("/\[IMG\](.+?)\[\/IMG\]/", "<img src=\"\\1\" border=\"0\">", $content); // Цитата $content = preg_replace("/\[Q\](.+?)\[\/Q\]/", "<b>Цитата:</b><br /><div class=\"quote\">\\1</div>", $content); // Смайлики $content = preg_replace("/\*(.+?)\*/", "<img src=\"/images/smiles/\\1.gif\" border=\"0\">", $content); return $content; } // Тест функции $text = "TEXT"; $text = bb_to_html($text); echo $text; ?> | И немного не правильную, но для БК Код: function vbcode($message) { $message = str_replace("\n", "<br>", $message); $message = preg_replace('/(\[b\])(.+?)(\[\/b\])/', '<b>\\2</b>',$message); $message = preg_replace('/(\[i\])(.+?)(\[\/i\])/', '<i>\\2</i>',$message); $message = preg_replace('/(\[u\])(.+?)(\[\/u\])/', "<u>\\2</u>", $message); $message = preg_replace('/(\[quote\])(.+?)(\[\/quote\])/', "<br><b><a class=quote>Цитата:</a></b><br><div class=\"news_quote\">\\2</div>", $message); $message = preg_replace('/(\[img\])(.+?)(\[\/img\])/', "<img border=0 src=\"\\2\">", $message); $message = preg_replace('/(\[url\])(.+?)(\[\/url\])/', "<a href=\"\\2\" target=\"_blank\">\\2</a>", $message); $message = preg_replace('/(\[url=(.+?)\])(.+?)(\[\/url\])/', "<a href=\"\\2\" target=\"_blank\">\\3</a>", $message); $message = preg_replace('/(\[center\])(.+?)(\[\/center\])/', '<center>\\2</center>',$message); $message = preg_replace("/\[inf\](.*)\[\/inf\]/iseU", "LoadInfo(\"\\1\")", $message); $message = preg_replace('/(\[klan\])(.+?)(\[\/klan\])/', "<img width=\"24\" height=\"15\" src=\"http://img.combats.ru/i/klan/\\2.gif\" alt=\"\">", $message); $message = preg_replace('/(\[klan=(.+?)\])(.+?)(\[\/klan\])/', "<img width=\"12\" height=\"15\" src=\"images/align/align\\2.gif\"><img width=\"24\" height=\"15\" src=\"http://img.combats.ru/i/klan/\\3.gif\" alt=\"\">", $message); $message = preg_replace('/(\[pers\])(.+?)(\[\/pers\])/', "<nobr><b>\\2</b> <a href=\"http://capitalcity.combats.ru/inf.pl?login=\\2\" target=\"_blank\"><img width=\"12\" height=\"11\" border=\"0\" src=\"images/inf.gif\" alt=\"\"></a></nobr>", $message); $message = preg_replace('/(\[pers=(.+?)\|(.+?)\])(.+?)(\[\/pers\])/', "<nobr><b>\\4</b>\[\\2\]<a href=\"http://capitalcity.combats.ru/inf.pl?login=\\4\" target=\"_blank\"><img width=\"12\" height=\"11\" border=\"0\" src=\"images/inf/inf\\3.gif\" alt=\"\"></a></nobr>", $message); $message = preg_replace('/(\[pers=(.+?)\])(.+?)(\[\/pers\])/', "<nobr><b>\\3</b>\[\\2\]<a href=\"http://capitalcity.combats.ru/inf.pl?login=\\3\" target=\"_blank\"><img width=\"12\" height=\"11\" border=\"0\" src=\"images/inf.gif\" alt=\"\"></a></nobr>", $message); $message = preg_replace('/(\[block\])(.+?)(\[\/block\])/', '<a class="block">\\2</a>',$message); $message = preg_replace('/(\[htext=(.+?),(.+?)\])(.+?)(\[\/htext\])/', '<a id=\'bhidden_\\2\' style="CURSOR: pointer" onclick="show_hide(\'hidden_\\2\',\'<b>\\3</b>\',\'<b>скрыть</b>\')\;"><b>\\3</b></A><span id=\'hidden_\\2\' style="DISPLAY: none"><br />\\4</span>', $message); $message = preg_replace('/(\[color=(.+?)\])(.+?)(\[\/color\])/', '<font color=\"\\2\">\\3</font>',$message); $message = preg_replace('/(\[size=(.+?)\])(.+?)(\[\/size\])/', '<font size=\"\\2\">\\3</font>',$message); $message = preg_replace('/(\[city\])(.+?)(\[\/city\])/', "<img src=\"images/cities/small/\\2.gif\" alt=\"\"><b>\\2City</b>", $message); $message = preg_replace('/(\[city=(.+?)\])(.+?)(\[\/city\])/', "<img src=\"images/cities/small/\\2.gif\" alt=\"\"><b>\\3</b>", $message); $message = preg_replace('/(\[align\])(.+?)(\[\/align\])/', "<img height=\"15\" src=\"images/align/align\\2.gif\">", $message); $message = preg_replace('/(\*(.+?)\*)/', "<img src=\"images/smiles/\\2.gif\" border=\"0\">", $message); $message = stripslashes($message); return $message; } |
|