用PHP中的html替换新行 [英] Replacing a new line with its html equivalent in PHP

查看:116
本文介绍了用PHP中的html替换新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个难题,我需要用<br />替换新行.现在,很明显,替换所有\ n实例都行不通,因为该页面没有适当的换行符.这是一些可能的文本的示例:

I am facing a bit of a quandary, I need to replace a new line with <br />. Now, clearly, replacing all instances of \n did not work, as the page did not have proper linebreaks. Here is an example of some possible text:

Some text


More text

现在,这是一个问题,因为没有\ n,而且我无法自动插入<br />.如何确保其中包含正确的换行符?

Now, this is an issue because there is no \n and I have no way to auto-insert <br />. How can I ensure that this contains proper linebreaks?

这是在PHP中.我不能将其用作纯文本.

This is in PHP. I cannot serve it as plain text.

推荐答案

要将新的换行符替换为
,只需使用

To replace new line breaks with
just use nl2br

这篇关于用PHP中的html替换新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆