如何保留 HTML 标签
&
从转换为和</p>
我有一个文本框可以更新/编辑我的数据库,在尝试让它实际工作数千次错误之后,我现在[希望]处于最后阶段!
目前没有这些编辑页面,我的网站的工作方式是我在数据库中有一段文本,例如
[p]这是示例文本[/p]
[p]这是更多示例文本,将在下一段[/p]
当它回显到网站时,html 标签消失,文本的格式完美地符合我想要的格式。
然而,当我添加新页面或编辑现有文本时,我最终会得到我在文本框中所写的内容,并在网站中回显。
我能做什么来阻止这种情况发生?
这是代码
<form id="form" name="form" method="post" action="page_edit_parse.php" onsubmit="return validate_form ( );">
<textarea name="pagebody" id="pagebody" cols="88" rows="16"><?php echo $pagebody; ?></textarea>
<input name="pid" type="hidden" value="<?php echo $pid; ?>" />
<input type="submit" name="button" id="button" value="Submit Page Edit" />
</form>
I have a text box that updates/edits my database, after thousands of errors trying to get it to actually work I am now at [hopefully] the final stage!
At the moment without these edit pages, how my website is working is that I have a block of text in the database for example
[p]This is sample text[/p]
[p]This is some more sample text that will be in the next paragraph[/p]
And when it echoes out into the site the html tags disappear and the text perfectly formatted exactly how I want it to be.
However, when I add a new page or edit the existing text I end up with exactly what I wrote in the text box echoing out into the website.
What can I do to stop this happening?
Here is the code
<form id="form" name="form" method="post" action="page_edit_parse.php" onsubmit="return validate_form ( );">
<textarea name="pagebody" id="pagebody" cols="88" rows="16"><?php echo $pagebody; ?></textarea>
<input name="pid" type="hidden" value="<?php echo $pid; ?>" />
<input type="submit" name="button" id="button" value="Submit Page Edit" />
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当页面显示时,文本区域($pagebody)的内容被解释为html,这就是标记“消失”的原因。但是,当您提交表单时,文本区域内容将被编码,以保留您的输入。接收脚本可以在将 pagebody 值写入数据库之前对其进行解码。请参阅此相关文章:php htmlentities 来解码文本区域。
When the page is displayed, the content of the textarea ($pagebody) is interpreted as html, which is why the markup tags "disappear". However, when you submit the form, the textarea content is encoded, to preserve your input. The receiving script can decode the pagebody value before writing it to the database. See this related post: php htmlentities to decode textarea.