控制容器中的自动换行

发布于 2024-09-12 05:31:44 字数 553 浏览 5 评论 0原文

我有一个特殊的问题。我有一个电子邮件组,通过管道将电子邮件发送到留言板。电子邮件的换行方式各不相同。在雅虎,消息往往会填满留言板上的整个容器。但在所有其他邮件客户端中,只有部分容器宽度被填充,因为原始邮件已被包装。我希望所有电子邮件填充容器的整个宽度。我想到了两种可能的解决方案:CSS 或消除换行符的正则表达式。因为我只是一名车库机械师(从事此类工作),所以我根本无法完成这项工作。有什么帮助吗?

以下是显示问题的链接: http://seanwilson.org/forum/index.php?t=msg&th=1729&start=0&S=171399e41f2c10c4357dd9b217caaa3f (将“sean”的消息与“rob”的消息进行比较。一个填满了容器,另一个则没有)。

你们中有人能建议如何让所有邮件填满容器吗?

I have a peculiar problem. I have an email group that pipes emails to a message board. The word wrap of the emails varies. In yahoo, the messages tend to fill the entire container on the message board. But in all other mail clients, only part of the container width is filled, because the original mail was wrapped. I want all of the email messages to fill the entire width of the container. I've thought of two possible solutions: CSS, or a Regex that eliminates line breaks. Because I am only a garage mechanic (at these sorts of things), I simply cannot get the job done. Any help out there?

Here is a link that shows the issue: http://seanwilson.org/forum/index.php?t=msg&th=1729&start=0&S=171399e41f2c10c4357dd9b217caaa3f
(compare the message of "sean" with that of "rob." One fills the container, the other not).

Can any of you suggest how to get all the mail to fill the container?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦初启 2024-09-19 05:31:44

您提供的信息太少 - 您使用什么编程语言 - PHP/Javascript/有什么不同吗?

我认为你只需要用空格替换 \n、\r 和 \r\n 即可。 PHP 代码:

$nowrap = str_replace('\r\n', ' ', $nowrap);
$nowrap = str_replace('\r', ' ', $nowrap);
$nowrap = str_replace('\n', ' ', $nowrap);

您可以在其他语言中进行类似的操作(对于 JS,请参阅 string.replace 方法: http://www.tizag.com/javascriptT/javascript-string-replace.php)。

You gave too little information - what programming language are you using - PHP/Javascript/anything different?

I think you only need to replace \n, \r and \r\n with whitespace. PHP code for that:

$nowrap = str_replace('\r\n', ' ', $nowrap);
$nowrap = str_replace('\r', ' ', $nowrap);
$nowrap = str_replace('\n', ' ', $nowrap);

You can do that analogically in other languages (for JS see string.replace method: http://www.tizag.com/javascriptT/javascript-string-replace.php).

匿名。 2024-09-19 05:31:44

根据具体情况(人们似乎总是在段落之间添加 2 个换行符),您可以说问题是:用空格替换所有不直接在换行符之前或之后的换行符。

//just to be sure, remove \r's
$string = str_replace("\r",'',$string);
$string = preg_replace('/(?<!\n)\n(?!\n)/',' ',$string);

在允许 \r 的同时:

$string = preg_replace('/(?<!\r|\n)\r?\n(?!\r|\n)/',' ',$string);

编辑:没关系:不要使用:虽然人们倾向于在段落中编写电子邮件文本,但您使用此正则表达式破坏他们的签名/签收。人们可以在认为它“可破坏”之前摆弄最小行长(我选择了 63),但它会很繁琐:

$string = preg_replace('/([^\r\n]{63,})\r?\n(?!\r|\n)/','$1 ',$string);

问题是:无法保证换行不是故意的。通过可调整的行长度,您可以将其基于普通用户,但问题是:他们更介意什么:破坏和破坏之间的差异?不间断的段落,还是破坏他们的签名?

Depending on the situation (people always seem to add 2 linebreaks between paragraphs), you could say the problem is: replace all newlines not directly preceded or followed by a newline with a space.

//just to be sure, remove \r's
$string = str_replace("\r",'',$string);
$string = preg_replace('/(?<!\n)\n(?!\n)/',' ',$string);

While allowing \r's:

$string = preg_replace('/(?<!\r|\n)\r?\n(?!\r|\n)/',' ',$string);

Edit: nevermind: do not use: while people tend to write their email text in paragraphs, you will break their signature / signoff with this regex. One could fiddle around with a minimum linelength before deeming it 'breakable' (i chose 63), but fiddly it will be:

$string = preg_replace('/([^\r\n]{63,})\r?\n(?!\r|\n)/','$1 ',$string);

The problem is: there are no assurance the linebreak wasn't intended. With a fiddleable line-length you could base it on average users, but the question is: what do they mind more: the differences between breaking & non-breaking paragraphs, or the breaking of their signatures?

未蓝澄海的烟 2024-09-19 05:31:44

谢谢你这么快就回来了!

讨论板使用 php(以及 CSS)。唯一的麻烦是我修改其编程的能力有些有限。如果我要以我目前的技术水平做到这一点,我只有两个选择之一。

  1. 在 php.ini 中使用 preg-replace讨论板允许我们从控制面板执行此操作。因此,如果我可以用一个 preg-replace 语句来完成它,它应该可以工作。

如果我不删除 \r,Wrikken 的解决方案会起作用吗?因为这似乎是正确的。 (可以将 \r 添加到 preg-replace 中吗?)

  1. 我希望解决方案可以通过某种 css 属性来实现。我想那是不可能的。

非常感谢您的帮助!

[注:非常感谢您的帮助!解决方案有效!我把数字改为53左右。它需要小一点。我不在乎罕见的长签名行可能会丢失回车符。对于一个完整的消息框来说,这是一个很小的代价!你轻松地让我节省了几天的学习时间,这些东西注定会令人沮丧,非常感谢你的快速解决。我很高兴在这里收到的帮助。]

Thanks for getting back so quickly!

The discussion board uses php (and also CSS). The only trouble is that I am somewhat limited in my ability to tinker with its programing. If I am to do this at my current level of skilty, I have only one of two options.

  1. using a preg-replace in php. The discussion board allows us to do this from a control panel. So If I could do it with one preg-replace statement, it should work.

Would Wrikken's solution work if I do not remove \r's? Because that seems to be spot on. (could the \r's be added to the preg-replace?)

  1. I had hoped the solution could come through a css property of some sort. I guess that isn't possible.

Thanks so much for your help!

[NOTE: thanks so much for your help! The solution worked!!! I changed the number to 53 or so. It needed to be a little smaller. I don't care that a rare, long signature lines may lose its carriage return. That's a small price to pay for a full message box! You easily saved me several days of learning something that was bound to be moderately frustrating, Thanks so much for that quick fix. I am joyous at the help I received here.]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文