简体   繁体   English

修改HTML的文本区域-渲染换行符

[英]Text area to modify HTML - rendering line breaks

I'm loading a portion of an HTML page into a text area so that I can make small changes. 我正在将HTML页面的一部分加载到文本区域中,以便进行一些小的更改。 All the HTML tags are shown along with the text, which is what I need to happen; 所有HTML标记都与文本一起显示,这是我需要做的; I don't want a WYSIWYG editor or anything fancy. 我不需要所见即所得的编辑器或任何花哨的东西。

The one thing I want is for line breaks to be shown in the text area in addition to the <p></p> and <h1></h1> tags otherwise it's a giant wall of text and it's really hard to proof read. 我想做的一件事是,除了<p></p><h1></h1>标记外,还要在文本区域中显示换行符,否则这是一堵巨大的文字墙,确实很难证明阅读效果。 I don't want the line breaks to be doubled after I save the modifications though as the next step will be to convert everything in the text area to a PDF file. 我不希望在保存修改后将换行符加倍,因为下一步是将文本区域中的所有内容转换为PDF文件。

ETA: nl2br() doesn't work because there are no line breaks to begin with. ETA:nl2br()不起作用,因为开始时没有换行符。 The content is assembled from paragraphs in a MySQL database using a loop. 内容是使用循环从MySQL数据库中的段落中组合而成的。 The

tags are inserted during the loop too. 标签也在循环中插入。

What's the best way to do this? 最好的方法是什么? I'm using PHP. 我正在使用PHP。

Oh, PS - I'm aware of the security concerns of not stripping the tags. 哦,PS-我知道不剥离标签的安全问题。 This page is for the admin (me) only and will be password protected. 该页面仅适用于管理员(我),并且将受密码保护。

Maybe you can filter those first, before showing to textarea ? 也许您可以在显示到textarea之前先对其进行过滤? Something like this, maybe (add newline after the closing tag): 可能是这样的(在结束标记后添加换行符):

$rawhtml = str_replace(array("</p>", "</h1>"), "\n", $rawhtml);

在将数据发送到textarea之前,将变量放在nl2br()函数中,然后将其发送到textarea。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM