JS Chat / Problem with special characters

JavaScript related questions should go here.
Post Reply
Posts: 26
Joined: Fri Jun 15, 2012 1:03 pm

JS Chat / Problem with special characters

Post by SicX »

Hey guys,
I'm having some trouble with my JS Chat! Special characters like ° and `´ or ß don't work. (charset UTF-8)
For the first 2,5 sec. (until chat reloads log) it seems fine but then ß will turn into ß aso.


[syntax=php]<div id="Chatwrapper">
<div id="Chatmenu">
<div style="clear:both"></div>
<div id="chatbox"><?php
if(file_exists("log.html") && filesize("log.html") > 0){
$handle = fopen("log.html", "r");
$contents = fread($handle, filesize("log.html"));

echo $contents;

<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" size="60">
<input name="submitmsg" type="submit" id="submitmsg" value="Senden" />

[syntax=javascript]<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
var objDiv = document.getElementById("chatbox");
objDiv.scrollTop = objDiv.scrollHeight;

// jQuery Document
//If user submits the form
var clientmsg = $("#usermsg").val();
$.post("post.php", {text: clientmsg});
$("#usermsg").attr("value", "");
return false;

//Load the file containing the chat log
function loadLog(){
var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
url: "log.html",
cache: false,
success: function(html){
$("#chatbox").html(html); //Insert chat log into the #chatbox div
var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
setInterval (loadLog, 2500); //Reload file every 2.5 seconds

$text = $_POST['text'];

$fp = fopen("log.html", 'a');
fwrite($fp, "<div class='msgln'>(".date("H:i:s").") <b>".$_SESSION['username']."</b>: ".stripslashes(htmlspecialchars($text, ENT_QUOTES, UTF-8))."<br></div>");

thinking of an str_replace(); ? (ß -> &szlig;)

Hope anyone can help me :)
Post Reply