Chat писане

Примерно като напишеш в чата "(happy)" за да ти го изкара на картинка а не надпис - ще стане с този код:

$message = str_replace("(happy)","<img src=емотиконка.gif>",$message);

И така за всички емотиконки добавяш по 1 ред.
 
а искам да попитам как да направя във чата ми само аз да пиша цветно а другите които постват поста им да е със бели букви
 
if($row[username] == admin){
echo "<font color="red">$text"</font>";
}
else{
echo "$text";
}

Код:
<?php
$query = mysql_query("SELECT * FROM `chat` ORDER BY id DESC")or die(mysql_error()."<br />ред: ".__LINE__);
while ($row = mysql_fetch_array($query)) {
$text =$row['text'];

if($row[username] == admin){
echo "<font color="red">$text</font><br />";
}
else{
echo "$text<br />";
}

}
?>

:idea:
 
proba каза:
Примерно като напишеш в чата "(happy)" за да ти го изкара на картинка а не надпис - ще стане с този код:

$message = str_replace("(happy)","<img src=емотиконка.gif>",$message);

И така за всички емотиконки добавяш по 1 ред.

да но нещо не се получава каде трябва точно да го сложа
 
Ами там където изкарваш съобщенията от чата чрез променлива.
Примерно nom3r1 направи това за цвета.
Ще използвам неговия код за да добавя и това за съобщенията.

<?php
include "конфиг файл";
$query = mysql_query("SELECT * FROM `chat` ORDER BY id DESC")or die(mysql_error()."<br />ред: ".__LINE__);
while ($row = mysql_fetch_array($query)) {
$text =$row['text'];
$text = str_replace("(happy)","<img src=емотиконка.gif>",$text);
$text = str_replace("(sad)","<img src=емотиконка2.gif>",$text);
$text = str_replace("(rofl)","<img src=емотиконка3.gif>",$text);

if($row[username] == admin){
echo "<font color="red">$text</font><br />";
}
else{
echo "$text<br />";
}

}
?>

Само си добаявш и още емотиконки , по начина които е оцветен в червен цвят.
 
Е неможе да не става.
Друг е въпроса , че неможеш да го направиш.
Дай кода който изкарва съобщенията от чата.
 
Това ли е ако не ще ти дам друго

<?
session_start();

if(isset($_GET['logout'])){

//Simple exit message
$fp = fopen("log.html", 'a');
fwrite($fp, "<div class='msgln'><i>User ". $_SESSION['name'] ." has left the chat session.</i><br></div>");
fclose($fp);

session_destroy();
header("Location: index.php"); //Redirect the user
}

function loginForm(){
echo'
<div id="loginform">
<form action="index.php" method="post">
<p>Please enter your name to continue:</p>
<label for="name">Name:</label>
<input type="text" name="name" id="name" />
<input type="submit" name="enter" id="enter" value="Enter" />
</form>
</div>
';
}

if(isset($_POST['enter'])){
if($_POST['name'] != ""){
$_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
}
else{
echo '<span class="error">Please type in a name</span>';
}
}
?>

<head>
<title>Chat - Customer Module</title>
<link type="text/css" rel="stylesheet" href="chat.css" />
</head>

<?php
if(!isset($_SESSION['name'])){
loginForm();
}
else{
?>
<div id="wrapper">
<br><br>
<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="63" />
<input name="submitmsg" type="submit" id="submitmsg" value="Изпрати" />
</form>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
// 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

//If user wants to end session
$("#exit").click(function(){
var exit = confirm("Are you sure you want to end the session?");
if(exit==true){window.location = 'home.php?logout2true';}
});
});
</script>
<?php
}
?>
</body>
</html>
 

Back
Горе