I have a problem with multiple email forms in various sites. They are all submitted and processed by the same PHP module, so it makes sense to correct it there. Due to a bug in some older browsers I still support, I had to make all my mailform “textarea” fields use the “wrap=’phsyical” (same as wrap=hard) attribute. Otherwise the visitors entered text would cause the textarea to scroll horizontally at the right edge instead of “soft’ wrapping as they type. (In other words, wrap=”soft” or wrap=”virtual” wasn’t always working right in all browsers). Maybe this is no longer a problem in modern browsers, but for now I just want to correct the problem in the common PHP module.
Its easy enough to scan the PHP variable holding the textarea data, replacing all occurrences of the CR/LF combination with a space character. But when a visitor is using the form they are likely to format their message themselves, putting two line breaks where they want a paragraph break. So my routine will have to make sure that occurrences of two CR/LF combinations are left alone.
OK, this is not rocket science, and I guess I could come up with a routine to do it. But it seems like such a common problem, I though maybe it was a wheel that didn’t need to be reinvented, or maybe there is already a library function to do exactly what I’m looking for. So any suggestions are appreciated. I have an idea, but I’m not really good at regex, so don’t laugh…
“`
function removeSingleLinefeeds($string) {
return preg_replace(‘~R{1,}~’, ”, $string);
}
Thanks!