views:

429

answers:

3

Hi,

I use a php form processor script that works fine. Except when users submit text in a multi-line text field, any line breaks or new lines are stripped out of the resulting string variable that is passed on. This often makes it unreadable by whoever receives the form results.

I'm no php expert but am sure the answer lies in the code that is stripping characters. What I'm unsure of is if I stop it stripping characters will this result in a security risk?

The strip array reads:

array('*', '|', '>', '<', '/', '\\\', '\"', 'Bcc', 'BCC', 'bcc');

What can I change here to retain the line breaks?

Thanks in advance for any help.

+1  A: 

I believe you have an issue at the rendering phase. Have you tried:

echo nl2br($text);

Where $text is the text you're talking about.

Ionuț G. Stan
+1  A: 

Nothing there is stripping line breaks.

It's more likely that you're not doing anything on the display side to make the line breaks display. You're outputting HTML, and to HTML a line break is just more whitespace. You'll probably benefit from applying nl2br().

chaos
A: 

If your problem is with the submitted string then this means that the submitted string did not contain any line breaks or newline chars.

In one occassion i looked up the wrap="(hard|physical)" attribute on the text area. Some values of this attribute force the textarea to maintain line-breaks in the user text.

Did you try using nl2br($text) on the submitted text;

andreas
This worked first time. Many thanks. Looks like everyone else suggested similar things too.
TheTub