用电子邮件替换回车 [英] Replace carriage return in an email

查看:92
本文介绍了用电子邮件替换回车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在PHP中用换行符替换回车符,以便我的站点管理员在每次他们想要在从我的站点输入电子邮件时添加新行时不必输入
。我尝试了几种不同的方法来替换换行符,但都没有成功。我试过的方法是:

I'm trying to replace carriage returns with a line break in PHP so that my site moderators don't have to type
every time they want to add a new line when typing an email from my site. I've tried several different methods to replace the line breaks but none have worked. The methods that I have tried are:

preg_replace('/\r\n?/', "<br />", $str);
eregi_replace(char(13), "<br />", $str);
str_replace("\r\n", "<br />", $str);
str_replace("\n", "<br />", $str);

和nl2br函数。

I我在谷歌上找了大约半个小时的答案,但还没有找到任何答案。任何人都可以提供帮助吗?

I've looked for the answer on Google for about half an hour and haven't found anything. Can anyone help?

推荐答案

php.net很好的例子文档

Quite good example from php.net documentation

// Order of replacement
$str     = "Line 1\nLine 2\rLine 3\r\nLine 4\n";
$order   = array("\r\n", "\n", "\r");
$replace = '<br />';

// Processes \r\n's first so they aren't converted twice.
$newstr = str_replace($order, $replace, $str);

这篇关于用电子邮件替换回车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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