PHP换行符不起作用 [英] PHP New Line Not Working

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

问题描述

可能重复:
为什么PHP回显文本会丢失其格式?

Possible Duplicate:
Why does PHP echo'd text lose it's formatting?

我无法让新行正常工作.它只是一行而已.像这样-

I cant get the new line to function work right. It just comes out as one line. Like this -

Make: Sony Model: a Processor: Intel Core 2 Duo

这是它的代码---

$message="Make: " . $_POST['make'] . "\r\n Model: " . $_POST['model'] . "\r\n Processor: " . $_POST['processor'];

当它作为电子邮件发送时,它可以正常工作,但是当我这样做时

When this is sent as an email it works perfect but when i do

echo $message;

它如上所示-全部集中在一行上.我该如何进行这项工作?

it just comes out as the above - it all on one line. How can i make this work?

谢谢

推荐答案

您大概是在将其回显到网页上.

You are presumably echoing this onto a web page.

浏览器不(或至少不应该)尊重字面上的换行符,您必须改用HTML <br>标记.

Browsers do not (or at least, should not) respect literal new lines, you have to use the HTML <br> tag instead.

尝试一下:

echo str_replace(array("\r\n","\r","\n"),'<br>',$message);
// or
echo nl2br($message);

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

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