Forum Moderators: coopster
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?
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
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
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]
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.