Jump to content

store whitespace but not interpret it in <br>


ktsirig

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?
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.