<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<?
include 'conn.php';
$connect=mysql_pconnect("$dbserver","$dbuser","$dbpass") or die ( 'Не мога да осъществя връзка с базата данни' );
mysql_select_db("$dbname") or die ( 'Не мога да се свържа с базата данни' );
$query = mysql_query("SELECT name, text FROM chat ORDER BY posted DESC");
while (list ($name, $text)=mysql_fetch_array ($query))
{
$text = preg_replace("/\[url\](.+?)\[\/url\]/s", '<a href="$1" onclick="window.open(this.href); return false;">$1</a>', $text);
$text = preg_replace("/\[url\=(.+?)\](.+?)\[\/url\]/s", '<a href="$1" onclick="window.open(this.href); return false;">$2</a>', $text);
$text = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "$1<a href=\"$2\" onclick=\"window.open(this.href); return false;\">$2</a>", $text);
$text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "$1<a href=\"http://$2\" onclick=\"window.open(this.href); return false;\" >$2</a>", $text);
$text = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "$1<a href=\"mailto:$2@$3\">$2@$3</a>", $text);
echo "<b><font color=red>$name</font></b>: $text<br/>";
}
?>