| Autor | Zpráva | ||
|---|---|---|---|
| Michal Sebek Profil |
Jak na svých stránkách přidám smajlíky do chatu? Smajlíky mám, jen jak udělám, aby se např. místo :D ukázal rozesmátý smajlík?
Kód chatu: <?
session_start();
if(!isset($_SESSION['prihlasen']) and @$_SESSION['prihlasen']!=1){
echo "<h1>Tato stránka je jen pro registrované</h1>";
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<style>
.msgln {
margin:0 0 2px 0;
}
</style>
<title>MISEBO CHAT</title>
</head>
<div id="chatbox" style="text-align:left; margin-bottom:25px; padding:10px; background:grey; height:270px; width:450px; overflow:auto; color:white; font:12px arial; border-radius:10px">
<?php
if(file_exists("chat.html") && filesize("chat.html") > 0){
$handle = fopen("chat.html", "r");
$contents = fread($handle, filesize("chat.html"));
fclose($handle);
echo $contents;
}
?></div>
<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" placeholder="Zpráva" style="width:395px; background-color:white" />
<input name="submitmsg" type="submit" id="submitmsg" value="Odeslat" style="width:60px; background-color:white" />
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//If user submits the form
$("#submitmsg").click(function(){
var user_msg = $("#usermsg").val();
$.post("post.php", {text: user_msg});
$("#usermsg").attr("value", "");
return false;
});
//function to load the chat file contents into chatbox and to scroll automatically
function loadLog(){
var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
$.ajax({
url: "chat.html",
cache: false,
success: function(html){
$("#chatbox").html(html);
var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal');
}
},
});
}
setInterval (loadLog, 2000); //load the file every 2 seconds
});
</script>
</body>
</html>A zápis chatu do souboru chat.html: <?
session_start();
date_default_timezone_set('Europe/Prague');
if(isset($_SESSION['login'])){
$text = $_POST['text'];
$fp = fopen("chat.html", 'a');
fwrite($fp, "<div class='msgln'>(".date("H:i:s").") <b>".stripslashes(htmlspecialchars($_SESSION['login']))."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
fclose($fp);
}
?> |
||
| Joker Profil |
Michal Sebek:
Prostě uděláte nahrazení :D na <img src="adresa smajlíku" alt=":D" title=":D">
|
||
| Michal Sebek Profil |
#3 · Zasláno: 30. 10. 2014, 17:58:13
Joker:
Thx, ale jak? |
||
| mimochodec Profil |
#4 · Zasláno: 30. 10. 2014, 18:01:42
Michal Sebek:
http://cz1.php.net/manual/en/function.str-replace.php |
||
| Michal Sebek Profil |
#5 · Zasláno: 30. 10. 2014, 18:05:41
mimochodec:
Dík. |
||
| Taps Profil |
#6 · Zasláno: 30. 10. 2014, 22:12:01
|
||
|
Časová prodleva: 12 let
|
|||
0