Convert html tag in textarea to rich text

怎甘沉沦 提交于 2019-12-02 01:18:12
Vinod Louis

There is no way to to do HTML formatting inside textarea you will have to use ant editor, but if you want to show it in div then setting the attribute contentEditable="true" will do the trick

more references here (already asked on stackoverflow)

If you want to show only the HTML output, then use a div tag instead of textarea. Because, we cannot show Rendered HTML inside a textarea.

If you want to show HTML output and want that editable, use contenteditable attribute on div tag.

More about contenteditable and it's support can be found at

https://developer.mozilla.org/en-US/docs/Web/HTML/Content_Editable

You should use javascript based WYSIWYG HTML Editors like tinymce and CKEditor for this purpose.

Otherwise the HTML code will remain as they are (plain text).

But if you use the editors, the user will be able to edit the content and the content will be converted to rich text using javascript (and it's exactly what the editors will do for you magically).

WYSIWYG = What You See Is What You Get

tcgumus

You should use the code in here 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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!