删除
>从文本区域?
我试图在消息“原始消息”之后进行换行,我已经尝试过这样做,但它一直向我显示
---Original message---<br />
message
<textarea id="txtMessage" rows="10" cols="50"><?php echo nl2br(str_replace('<br/>', " ","---Original message---\n".$array['message']));?></textarea>
我想要这样的东西:
---Original message---
message
有什么建议吗?
I am trying to do a line break after the message "Original message", I have tried with this but It keeps showing me the
---Original message---<br />
message
<textarea id="txtMessage" rows="10" cols="50"><?php echo nl2br(str_replace('<br/>', " ","---Original message---\n".$array['message']));?></textarea>
I want something likes this:
---Original message---
message
any advise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这应该做你想做的事:
示例:
结果:
但是如果你尝试这个:
你会得到这个:
因此你应该在将 nl2br 保存到数据库之前不要使用它,否则每次尝试编辑文本时都必须删除
!只需在将其打印为文本时使用它即可。This should do what you want it to:
Example:
Result:
But if you try this:
you will get this:
Therefore you should not use nl2br before saving it to database, otherwise you have to get rid of
<br />
every time you try to edit text! Just use it when you print it out as text.应该是
should be
php 函数“nl2br”接受换行符,并将它们转换为 br 标签。如果您不希望这样,您应该将其删除:)。
呵呵,被瑞恩打败了。
The php function "nl2br" takes newlines, and converts them into br tags. If you don't want that, you should probably remove it :).
Heh, beaten by Ryan.
您正在尝试替换
,但原始文本有
(注意空格)。You're trying to replace
<br/>
, but the original text has<br />
(note the space).您正在删除 HTML 中断,然后将它们添加回来!查看您的代码:
首先,
str_replace
替换'
带有一个空格。然后,gt ;'
nl2br
为每个添加一个
它找到换行符(\n
)。删除
nl2br
调用就完成了。You are removing the HTML breaks, then adding them back! Look at your code:
First,
str_replace
replaces'<br/>'
with a space. Then,nl2br
adds a<br>
for every newline (\n
) it finds.Remove
nl2br
call and it's done.如果您想对除文本区域内的内容之外的所有文本执行 nl2br,您可以这样做:
If you want to do nl2br on all of the text except for what's inside the textarea you could do this: