-3

有人知道我的错误代码是什么:

$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;
}
4

1 回答 1

2

编辑:你甚至在本地安装了 PHP 吗?PHP 脚本需要在本地安装 EasyPHP 之类的东西。


听起来像是一个糟糕的 Content-Type 标头。

通常这会自动设置,但您可以尝试强制执行它并确保您拥有一切。

<?php header('Content-Type: text/html'); ?>
<html><head></head><body>
    <?php 
         $text = 'OK BOSS :-) ';
         $text = str_replace(':-)', '<img src="emoticons/smile.gif" />', $text);
         echo $text;
    ?>
</body></html>
于 2012-07-11T04:31:45.540 回答