subuntug Posted September 8, 2009 Report Share Posted September 8, 2009 Hello, I'm newbie into PHP and I have a little problem.I learned that if we put in shortcut like \n inside a string data, this make a new line in the out put text.But unfortunately, this never works for me. For example, the following code seems correct : <?phpecho "firstname= tata \n lastname=batata"?> While I expect to get two lines, the browser display all my string in one line.So, please, tell me where is the problem into my code.Thank you in advance Link to comment Share on other sites More sharing options...
Synook Posted September 8, 2009 Report Share Posted September 8, 2009 What does this have to do with regular expressions?Anyway, the browser doesn't display line breaks verbatim, unless you are in a pre block. So while you are actually printing out two lines, to make them appear on two lines inside a browser you need to use a <br> tag. If you want to use PHP to convert newlines to break tags there is the nl2br() function. Link to comment Share on other sites More sharing options...
jeffman Posted September 8, 2009 Report Share Posted September 8, 2009 It works. View the source and you'll see the line break exactly where you expect it.Remember that HTML treats ALL whitespace characters the same: as a space. Spaces, tabs, and newlines are all the same, and if more than one appears in a row, they will all be reduced to exactly one space.If you want an HTML line break, use <br> or <p>Be aware that this has nothing to do with regular expressions and almost nothing to do with PHP. I'm not complaining. It's just something you'll want to know. 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