Page 1 of 1

JS Chat / Problem with special characters

Posted: Wed Aug 07, 2013 5:17 pm
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.

Code:
<div id="Chatwrapper">
	<div id="Chatmenu">
		<div style="clear:both"></div>
	</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"));
		fclose($handle);
		
		echo $contents; 
	}
	?></div>
	
	<form name="message" action="">
		<input name="usermsg" type="text" id="usermsg" size="60">
		<input name="submitmsg" type="submit"  id="submitmsg" value="Senden" />
	</form>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jq ... "></script>
<script type="text/javascript">
var objDiv = document.getElementById("chatbox");
objDiv.scrollTop = objDiv.scrollHeight;

// jQuery Document
$(document).ready(function(){
	//If user submits the form
	$("#submitmsg").click(function(){
		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;
		$.ajax({
			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
});
</script>
	$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>");
	fclose($fp);
thinking of an str_replace(); ? (ß -> ß)

Hope anyone can help me :)
SicX