有人知道我的错误代码是什么:
$text = str_replace(":-)", "<img src='emoticons/smile.gif'>", $text);
当我尝试使用 PHP 回显打印文本时,它显示:
<img src='emoticons/smile.gif'>
我要做的就是在输入时显示图像:-)
谢谢你。
根据详细信息,这是我的代码如下:
function sendChat() {
$from = $_SESSION['username'];
$to = $_POST['to'];
$message = $_POST['message'];
$_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s', time());
$messagesan = sanitize($message);
if (!isset($_SESSION['chatHistory'][$_POST['to']])) {
$_SESSION['chatHistory'][$_POST['to']] = '';
}
$_SESSION['chatHistory'][$_POST['to']] .= <<<EOD
{
"s": "1",
"f": "{$to}",
"m": "{$messagesan}"
},
EOD;
unset($_SESSION['tsChatBoxes'][$_POST['to']]);
$sql = "insert into chat (chat.from,chat.to,message,send) values ('".mysql_real_escape_string($from)."', '".mysql_real_escape_string($to)."','".mysql_real_escape_string($message)."',NOW())";
$query = mysql_query($sql);
echo "1";
exit(0);
}
function sanitize($text) {
$text = htmlspecialchars($text, ENT_QUOTES);
$text = str_replace("\n\r","\n",$text);
$text = str_replace("\r\n","\n",$text);
$text = str_replace("\n","<br>",$text);
$text = str_replace(":-)", "<img src='emoticons/13.gif'>", $text);
return $text;
}