bjenn85 Posted September 5, 2015 Share Posted September 5, 2015 (edited) I have a simple bulletin board I'm working on and would to run all of my HTML inline for performance and/or OCD. Right now if I submit a message with multiple lines by hitting Enter and then you view the page source it breaks it up into several lines... example: I would like it to run those <br>'s inline with the rest of the source code instead of making a new line, but I'm having trouble figuring it out. I'm using this snippet below to find Enter spaces/new lines with "\n" and then using a <br> in place: function fixtabspa( $txt ) { $srch = array( "\n", "\t", ' ', ' ' ); $replc = array( '<br>', ' ', ' ', ' ' ); return str_replace( $srch, $replc, $txt ); } and on the posting form we call that function simply: $post_message = fixtabspa( $post_message ); Any clue on how to replace those \n's with <br>'s without making new lines in the source code? Thanks Edited September 5, 2015 by bjenn85 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 5, 2015 Share Posted September 5, 2015 Hard to make sense out of what you want with the incomplete code you provided. Are you viewing this code in a browser or a text editor? You say 'view source'. Does that mean you are using the browser's 'view source' command? If so, a <br> will not cause a line break (at least not in IE) so if that is the problem, then you have a \n char in the code already. I'm confused as to your reason for worrying about what the 'view source' gives you for format too. Why does it matter since most people aren't going to see this? Besides - removing the <br> and inserting the \n is going to ruin the html formatting of the page. Quote Link to comment Share on other sites More sharing options...
scootstah Posted September 5, 2015 Share Posted September 5, 2015 Performance has nothing to do with it. Having a new line character or not is going to make exactly zero difference on execution times. You either have a \n or a \r\n character. Quote Link to comment Share on other sites More sharing options...
bjenn85 Posted September 6, 2015 Author Share Posted September 6, 2015 I got it figured out using http://php.net/manual/en/function.nl2br.php $txt=str_replace(array("\r\n","\r","\n"),"<br>",$txt); return $txt;} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.