Ins1d3r Posted May 20, 2008 Report Share Posted May 20, 2008 Lūdzu palīdziet. Pasakiet ko vajadzētu nomainīt šajā kodā, lai ierakstītais piemērs: čatā parādītos tā pat nevis ar šiem ķeburiem, uzreiz saku es jau nomainīju encodingu uz utf-8 gan failā gan sql datubāzē. shoutbox.php <? require_once("include/bittorrent.php"); dbconn(); loggedinorreturn(); header("Content-Type: text/html; charset=utf-8"); if ($CURUSER) { ///////////session///////////////// mysql_query("UPDATE users SET page=1 WHERE id = " . $CURUSER["id"]) or sqlerr(__FILE__,__LINE__); /////////////////////////////////// } function decode_unicode_url($str) { $res = ''; $i = 0; $max = strlen($str) - 6; while ($i <= $max) { $character = $str[$i]; if ($character == '%' && $str[$i + 1] == 'u') { $value = hexdec(substr($str, $i + 2, 4)); $i += 6; if ($value < 0x0080) // 1 byte: 0xxxxxxx $character = chr($value); else if ($value < 0x0800) // 2 bytes: 110xxxxx 10xxxxxx $character = chr((($value & 0x07c0) >> 6) | 0xc0) . chr(($value & 0x3f) | 0x80); else // 3 bytes: 1110xxxx 10xxxxxx 10xxxxxx $character = chr((($value & 0xf000) >> 12) | 0xe0) . chr((($value & 0x0fc0) >> 6) | 0x80) . chr(($value & 0x3f) | 0x80); } else $i++; $res .= $character; } return $res . substr($str, $i); } function convert_text($s) { $out = ""; for ($i=0; $i<strlen($s); $i++) { $c1 = substr ($s, $i, 1); $byte1 = ord ($c1); if ($byte1>>5 == 6) // 110x xxxx, 110 prefix for 2 bytes unicode { $i++; $c2 = substr ($s, $i, 1); $byte2 = ord ($c2); $byte1 &= 31; // remove the 3 bit two bytes prefix $byte2 &= 63; // remove the 2 bit trailing byte prefix $byte2 |= (($byte1 & 3) << 6); // last 2 bits of c1 become first 2 of c2 $byte1 >>= 2; // c1 shifts 2 to the right $word = ($byte1<<8) + $byte2; if ($word==1025) $out .= chr(168); // ? elseif ($word==1105) $out .= chr(184); // ? elseif ($word>=0x0410 && $word<=0x044F) $out .= chr($word-848); // ?-? ?-? else { $a = dechex($byte1); $a = str_pad($a, 2, "0", STR_PAD_LEFT); $b = dechex($byte2); $b = str_pad($b, 2, "0", STR_PAD_LEFT); $out .= "".$a.$b.";"; } } else { $out .= $c1; } } return $out; } if ($_GET["do"] == "shout") { $shout = convert_text(urldecode(decode_unicode_url($_GET["shout"]))); if ($shout == "/prune" && get_user_class() >= UC_ADMINISTRATOR) { mysql_query("TRUNCATE TABLE shoutbox"); die("Сообшений нет"); } $sender = $CURUSER["id"]; if (!empty($shout)) { $shout = preg_replace("/\/me /", $CURUSER["username"]." ", $shout); $datee = time(); mysql_query("INSERT INTO shoutbox (date, text, userid) VALUES (".implode(", ", array_map("sqlesc", array($datee, $shout, $sender))).")") or sqlerr(__FILE__,__LINE__); } else print("<script>alert('Введи сообщение');</script>"); } elseif ($_GET["do"] == "delete" && get_user_class() >= UC_SECURITY && is_valid_id($_GET["id"])) { $id = $_GET["id"]; mysql_query("DELETE FROM shoutbox WHERE id = $id") or sqlerr(__FILE__,__LINE__); } $res = mysql_query("SELECT shoutbox.*, users.username, users.warned, users.id as uid, users.class FROM shoutbox INNER JOIN users ON shoutbox.userid = users.id ORDER BY id DESC LIMIT 35") or sqlerr(__FILE__,__LINE__); if (mysql_num_rows($res) == 0) die("Сообшений нет"); print("\n"); while ($arr = mysql_fetch_array($res)) { if ($arr["warned"] == "yes") $warn = "<img src=\"pic/warned.gif\" alt=\"Warned\"/>"; else $warn = ""; $username = $arr["username"]; $arr["text"] = format_comment($arr["text"]); $arr["text"] = str_replace("[$CURUSER[username]]","<font color=#000000></font><b style='color: green; background: #FFFFFF;'>$CURUSER[username]</b><font color=#000000></font>",$arr["text"]); $arr["text"] = preg_replace("/\[((\s|.)+?)\]/", "<font color=#000000></font><b style='color: black;'>[\\1]</b><font color=#000000></font>", $arr["text"]); if (strpos($arr["text"], "privat($CURUSER[username])") !== false) { $variabila = "privat($CURUSER[username])"; $nume = substr($variabila, 7); $nume = substr($nume, 0, strlen($nume)-1); $id = $arr['id']; if (($CURUSER["username"] == $nume) || ($CURUSER["id"] == "".$arr["userid"]."")) { $arr["text"] = str_replace("privat($CURUSER[username])","<b style='color: orange;'>".$CURUSER[username]."</b>",$arr["text"]); print("<span class='date'>[".strftime("%H:%M:%S",$arr["date"])."]</span>" . (get_user_class() >= UC_SECURITY ? "<span onclick=\"deleteShout($arr[id]);\" style=\"cursor: pointer; color: red; font-weight: bold; text-decoration: underline\"><img src=\"pic/warned2.gif\" style=\"border: 0px;\" /></span>" : "") . " <a target=_blank href=message.php?action=sendmessage&receiver=".$arr['userid']." title=\"Отправить ЛС\"><img src=\"pic/pn_inbox.gif\" border=\"0\"></a> <a href=userdetails.php?id=".$arr["uid"]." target='_blank'><img src=\"pic/info/guest.gif\" border=0 title=\"Посмотреть профиль\"></a> <a href=\"userdetails.php?id=".$arr["uid"]."\" onClick=\"parent.document.shoutform.shout.focus();parent.document.shoutform.shout.value='[b]".$username."[/b]: '+parent.document.shoutform.shout.value;return false;\">".get_user_class_color($arr["class"], $arr["username"]) . "</a>$warn: ".($arr["text"])."<br />\n"); } } else if ((($CURUSER["id"] == "".$arr["userid"]."") OR (get_user_class() >= UC_SECURITY)) AND (get_user_class() >= $arr["class"]) AND (strpos($arr["text"], "privat(") !== false)) { $arr["text"] = preg_replace("/privat\(([^()<>\s]+?)\)/i","<b style='color: #orange; background: #FFFFFF;'>{\\1}</b>", $arr["text"]); print("<span class='date'>[".strftime("%H:%M:%S",$arr["date"])."]</span>" . (get_user_class() >= UC_SECURITY ? "<span onclick=\"deleteShout($arr[id]);\" style=\"cursor: pointer; color: red; font-weight: bold; text-decoration: underline\"><img src=\"pic/warned2.gif\" style=\"border: 0px;\" /></span>" : "") . " <a target=_blank href=message.php?action=sendmessage&receiver=".$arr['userid']." title=\"Отправить ЛС\"><img src=\"pic/pn_inbox.gif\" border=\"0\"></a> <a href=userdetails.php?id=".$arr["uid"]." target='_blank'><img src=\"pic/info/guest.gif\" border=0 title=\"Посмотреть профиль\"></a> <a href=\"userdetails.php?id=".$arr["uid"]."\" onClick=\"parent.document.shoutform.shout.focus();parent.document.shoutform.shout.value='[b]".$username."[/b]: '+parent.document.shoutform.shout.value;return false;\">".get_user_class_color($arr["class"], $arr["username"]) . "</a>$warn: ".($arr["text"])."<br />\n"); } elseif (strpos($arr["text"], "privat(") !== false) { } else { print("<span class='date'>[".strftime("%H:%M:%S",$arr["date"])."]</span>" . (get_user_class() >= UC_SECURITY ? "<span onclick=\"deleteShout($arr[id]);\" style=\"cursor: pointer; color: red; font-weight: bold; text-decoration: underline\"><img src=\"pic/warned2.gif\" style=\"border: 0px;\" /></span>" : "") . " <a target=_blank href=message.php?action=sendmessage&receiver=".$arr['userid']." title=\"Отправить ЛС\"><img src=\"pic/pn_inbox.gif\" border=\"0\"></a> <a href=userdetails.php?id=".$arr["uid"]." target='_blank'><img src=\"pic/info/guest.gif\" border=0 title=\"Посмотреть профиль\"></a> <a href=\"userdetails.php?id=".$arr["uid"]."\" onClick=\"parent.document.shoutform.shout.focus();parent.document.shoutform.shout.value='[b]".$username."[/b]: '+parent.document.shoutform.shout.value;return false;\">".get_user_class_color($arr["class"], $arr["username"]) . "</a>$warn: ".($arr["text"])."<br />\n"); } } ?> Link to comment Share on other sites More sharing options...
andrisp Posted May 20, 2008 Report Share Posted May 20, 2008 SET NAMES utf8 ir ? Uzreiz pēc mysql_select_db() to vajag izsaukt. Link to comment Share on other sites More sharing options...
andrisp Posted May 20, 2008 Report Share Posted May 20, 2008 Ā, tik tagad pamanīju, ka problēma ir citur - tev tur konvertācija uz entītijām notiek -> izravē šito ārā convert_text(). Link to comment Share on other sites More sharing options...
Ins1d3r Posted May 20, 2008 Author Report Share Posted May 20, 2008 paldies, tavs padoms atrisināja problēmu. :) Link to comment Share on other sites More sharing options...
Recommended Posts