我想将html标签应用于变量。
代码:echo '<strong>'.$message['sender'].' Sent'.'</strong>';
输出:<strong>The actual message Sent</strong>
所需输出:实际发送消息
如何将强类应用于$ message变量?
完整的上下文代码::
<textarea name="message" disabled rows="6" style="resize:none;" placeholder="Loading...">
<?php
$messages = get_msg();
foreach($messages as $message){
echo '<strong>'.$message['sender'].' Sent'.'</strong>';
echo $message['message'].'<br/><br/>';
}
if(isset($_POST['send'])){
if(send_msg($_POST['sender'],$_POST['message'])){
echo 'Message Sent.';
}else{
echo 'Message failed to send';
}
}
?>
</textarea>
答案 0 :(得分:4)
您正在将HTML直接输出到textarea中。 Textareas只是纯文本,而不是富文本编辑器。有关textareas的更多信息可以在Mozilla Developer Network documentation
找到答案 1 :(得分:2)
你不需要<textarea>
,因为这是输出而不是输入。
尝试使用简单的<div>
,然后像<strong>
这样的html标签会按预期运行。试试这个例子
<div>
<?php
$messages = get_msg();
foreach($messages as $message){
echo '<strong>'.$message['sender'] .' Sent</strong><br/>';
echo $message['message'].'<br/><br/>';
}
if(isset($_POST['send'])){
if(send_msg($_POST['sender'],$_POST['message'])){
echo '<span style="color=blue">Message Sent.</span>';
}else{
echo '<span style="color=red">Message failed to send</span>';
}
}
?>
</div>