我正在使用PHP来填充textarea:
<textarea text-input" id="Desc" rows="15" wrap="soft" name="Desc"><?php echo $Desc; ?></textarea>
但textarea在其中显示HTML标签,我不想要。
<b>Analog And Digital System</b><br />
<b>Analog System:</b><br />
A string tied to a doorknob would be an analog system. They have a value that changes steadily over time and can have any one of an infinite set of values in a range. If you put a measuring stick or ruler at a specific point along the string, you can measure the string's value every so many seconds at that point. When you watch it move, you will see it moves constantly. It doesn't instantly jump up and down the ruler. <br />
<br />
<b>Digital System:</b><br />
A digital system would be to flick the light switch on and off. There's no 'in between' values, unlike our string. If the switch you are using is not a dimmer switch, then the light is either on, or off. In this case, the transmitter is the light bulb, the media is the air, and the receiver is your eye. This would be a digital system.<br />
基本上我要做的是转换<b>
标记以使内容变为粗体,将<br>
标记转换为新行。
我想在不使用任何编辑器的情况下这样做。
答案 0 :(得分:4)
如果您只想显示HTML输出,请使用div
代码而不是textarea
。因为,我们无法在textarea
内显示已渲染的HTML。
如果您想要显示HTML输出并希望其可编辑,请在contenteditable
代码上使用div
属性。
有关contenteditable
的更多信息,可以在
https://developer.mozilla.org/en-US/docs/Web/HTML/Content_Editable
答案 1 :(得分:1)
没有办法在textarea中进行HTML格式化,你必须使用ant编辑器,但是如果你想在div中显示它,那么设置属性contentEditable =“true”就可以了。
更多参考here(已在stackoverflow上询问)
答案 2 :(得分:1)
您应该使用基于javascript的 WYSIWYG HTML编辑器,例如tinymce和 CKEditor 。
否则HTML代码将保持原样(纯文本)。
但是如果您使用编辑器,用户将能够编辑内容,并且内容将使用javascript转换为富文本(这正是编辑们将为您神奇地做的事情)。
WYSIWYG =所见即所得
答案 3 :(得分:0)
您应该使用此处的代码Converting <br /> into a new line for use in a text area
<?
$text = "Hello <br /> Hello again <br> Hello again again <br/> Goodbye <BR>";
$breaks = array("<br />","<br>","<br/>");
$text = str_ireplace($breaks, "\r\n", $text);
?>
<textarea><? echo $text; ?></textarea>