Forum Moderators: coopster

Message Too Old, No Replies

store whitespace but not interpret it in <br>

         

ktsirig

10:32 pm on Apr 12, 2006 (gmt 0)

10+ Year Member



Hello all,

my problem is the following: I have a page where the user enters some data, let's say :

string1 = 'AGREHREHRHREHRE';
string2 = 'WEFEWGEWGEGEWGEGEGWG';

These data I use in another page, so I use the "<pre>" tag to display what the user has entered. The problem arrives when the user writes something like EWGEGEW EFGEGEW EGRGREGRE RGVFVDSVDS

This string, when I pass it into a variable, it is stored with newlines. I don't want to make any substitution of the newlines, as I want to preserve the spaces in the next page, and display the user's sequence as entered and not with 3 <br>'s, because there were 3 spaces in the original string...
any ideas?

JohnCanyon

12:56 am on Apr 13, 2006 (gmt 0)

10+ Year Member



OK.. Im not really sure what it is your trying to accomplish here, but I will attempt to solve your problem as I understand it.

If you want to cut the \n (newline) from a variable, you can simply use the chop() function.

Example> $newvariable = chop($_POST[passed_variable]);

If you want to remove the whitespace in between the text entered.

Example> $newvariable = str_replace(" ","",$_POST[passed_variable]);

If this does not solve your problem, you might want to clarify exactly what it is you are trying to accomplish.

Cheers,

J

ktsirig

6:37 am on Apr 13, 2006 (gmt 0)

10+ Year Member



Hey John, thanx for your time...
Maybe I wasn't clear, since I wrote the message late at night..
My problem is that , when the user enters some text with whitespaces, like :

Hello, I am a user

PHP stores the string, but treats the whitespace characters like newlines, and when I print the data, I get

Hello
I
am
a
user

instead of :
Hello I am a user

What I want is to store the whitespaces(if any) and print them again as whitespaces and not <br>'s

jatar_k

6:48 am on Apr 13, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



could also be an issue with the element it is being entered into, textarea?

you could also just use str_replace [php.net] to swap any <br> or \n or \r (whichever it is) for a space

<edit>added link to function page

[edited by: jatar_k at 4:07 pm (utc) on April 13, 2006]

henry0

11:30 am on Apr 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How could that happen in a regular “text area”?
Post some code.

Are we speaking about a CMS that does not supply a
“Copy and paste from MS”? if so you need to clean after MS.

Anyway as per jatar_k the suggested function str_replace will help
But go the manual and look at posted functions
If this is an MS problem a poster has offered a neat function.