将文本区域中的html标记转换为富格文本
Convert html tag in textarea to rich text
我正在使用PHP填充一个文本区域:
<textarea text-input" id="Desc" rows="15" wrap="soft" name="Desc"><?php echo $Desc; ?></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>
标记转换为新行。
我想在不使用任何编辑器的情况下完成它。
如果只想显示HTML输出,请使用div
标记而不是textarea
。因为,我们无法在textarea
中显示"渲染HTML"。
如果要显示HTML输出并希望其可编辑,请使用div
标记上的contenteditable
属性。
有关contenteditable
及其支持的更多信息,请访问
https://developer.mozilla.org/en-US/docs/Web/HTML/Content_Editable
没有办法在文本区域内进行HTML格式化,您必须使用ant编辑器,但如果您想在div中显示它,那么设置属性contentEditable="true"将实现
此处有更多参考资料(已在stackoverflow上询问)
为此,您应该使用基于javascript的WYSIWYGHTML编辑器,如tinymce和CKEditor。
否则,HTML代码将保持原样(纯文本)。
但是,如果您使用编辑器,用户将能够编辑内容,并且内容将使用javascript转换为富文本(这正是编辑器神奇地为您所做的)。
WYSIWYG=所见即所得
您应该使用此处的代码转换<br/>插入一个新行,用于文本区域
<?
$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>
正如其他人所解释的。我有一些解决方案,如下面的代码。实际上,我创建了一个div,然后将其转换为textarea然后是我的php代码。
它对我很有效,请马上试试。我想你已经得到了答案。
<div style="height: 100px;overflow-y: scroll;text-rendering:auto;overflow: auto;resize: vertical;">
<?php
//this is my chat.
$text = " Rohit | 14-04-2023 12:32:31
<b>nilesh bhai </b>
Rohit | 13-04-2023 19:17:17
<b>this is correct</b> ";
echo nl2br($text);
// answer is
// M3 Insurance | 14-04-2023 12:32:31
// **nilesh bhai**
// M3 Insurance | 13-04-2023 19:17:17
// **this is correct**
?>
</div>
- 将格式化的纯文本转换为HTML
- 使用带有文本转换的jquery获取文本
- 如何在节点.js上将文本转换为 Base58
- 将 Javascript 数组中的文本转换为超链接
- 输入占位符文本转换CSS样式
- JavaScript将缩进文本转换为HTML列表重复顶层<李>'s为<ul>'s
- Fabric.js文本转换不起作用
- 单击“编辑”按钮,将文本转换为文本框
- 在javascript中将转义文本转换为html
- JavaScript文本转换
- 正在将Fabric.js文本转换为路径
- Kendo UI-将Text()括起来的文本转换为<span>编码HTML
- 将Blob文本转换为Javascript中的数组/JSON对象
- javascript函数和HTML中的文本转换/动画onclick
- 将文本转换为 JavaScript 对象或数组
- jQuery - 将文本转换为谷歌地图链接
- 无法将文本转换为 JavaScript 数组
- Jquery/Javascript 解决方案,用于将 wiki 文本转换为 HTML,反之亦然
- 在 JavaScript 中将文本转换为日期/时间对象
- JS:将文本转换为对象数组