reportingsjr Posted October 31, 2006 Share Posted October 31, 2006 How could I do something like this forum, where if you hit enter and submit a post the enter stays, and everything doesnt just get reduced to one space? I have already tried the html <pre> tag but that seems to double all spaces for me... Odd! And it wouldnt be nl2br I dnot think because im not using \n or a text file.. Any thoughts? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 31, 2006 Share Posted October 31, 2006 It's still nl2br, when you hit enter it's the same character as \n represents, which is ASCII 10 I think. Link to comment Share on other sites More sharing options...
reportingsjr Posted October 31, 2006 Author Share Posted October 31, 2006 Ohhh, didnt realize that! So if I just did echo nl2br($post->content); it would do something like these forums? Hmm cool! Link to comment Share on other sites More sharing options...
shiftJIS Posted October 31, 2006 Share Posted October 31, 2006 The question has already been answered, but I do have my 2 cents.I tend to use regex instead of nl2br. The function is cool and all, but does tend to put a lot of linebreaks where it shouldn't belong intuitively if you allow html in the input. I make an expression that changes \n to <br /> in all situations except where it occurs before and after the end tag for block elements. Link to comment Share on other sites More sharing options...
reportingsjr Posted October 31, 2006 Author Share Posted October 31, 2006 Yeah, I used to say use regex. But they kept telling me it used extra overhead, which you dont want! Overhead means you use extra resources, in this case the regex engine (yes, it has its own engine...). So for this I say just use nl2br! Link to comment Share on other sites More sharing options...
shiftJIS Posted October 31, 2006 Share Posted October 31, 2006 Obviously, if you have make a feature that's more robust and intuitive, it'll have more overhead right? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 31, 2006 Share Posted October 31, 2006 Regex is the wrong thing to use when you're doing simple string replacement, for anything that requires pattern matching though it is the best choice. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now