Jump to content

Archived

This topic is now archived and is closed to further replies.

ktsirig

store whitespace but not interpret it in <br>

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Your question doesn't make any sense.

If I enter a string into a form and that string contains spaces, there is nothing in PHP that would automaticly convert the spaces into the "<br>" tags. If I were to enter a string that contains the newline character and you echo it without surrounding the string with the '<pre></pre>' tags, then it looks like the newline character have been converted to spaces, but if you do a "show source" you will see they are still there. This is a side affect of how HTML renders strings. If you want to display the lines as entered, you can use the nl2br() function when you echo it. This function will add the "<br />" tag before each newline character.

Please post either a better explanation of your problem and/or code that illustrates it.

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.