jquery, php, ajax로 채팅 시스템을 만들었습니다. 채팅 창에 html 로그의 마지막 10 줄을 표시하고 싶습니다. 어떻게채팅 시스템 로그 문제
...
echo "<div id='chatbox'>";
if(file_exists("log.html") && filesize("log.html") > 0){
$handle = fopen("log.html", "r");
$contents = fread($handle, filesize("log.html"));
fclose($handle);
$lastfifteenlines = array_slice(explode("<br>",file_get_contents($contents)),-10);
echo $lastfifteenlines;
}
echo "</div>";
그러나 로그에서 모든 것을 보여주는 것 :
이<div class='msgln'><b>Brian</b>: dd<br></div><div class='msgln'><b>Brian</b>: ddf<br></div><div class='msgln'><b>Arne</b>: PIS!<br></div><div class='msgln'><b>Brian</b>: sdfsdf sdfsdffds sdfdsf sdf sdf dfs dfsdf sdf sfd sfd fsd fsd sdf sdffsd sd fsdfsd fsd fsd<br></div><div class='msgln'><i>Brian er kommet på chatten.</i><br></div>
내 PHP는 이제 다음과 같습니다
log.html이 같이 보입니다 마지막 10 줄만 보여줄 수 있습니까? 마지막 10 번은 br이 발생 했나요?
편집 :
아약스와 JQuery와 :
function loadLog(){
var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height before the request
$.ajax({
url: "log.html",
cache: false,
success: function(html){
$("#chatbox").html(html); //Insert chat log into the #chatbox div
//Auto-scroll
var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height after the request
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
}
},
});
}
왜 이런 종류의 데이터베이스를 사용하지 않습니까? 형식화 된 데이터를 구문 분석하는 것은 결코 좋은 생각이 아닙니다. – Hidde