|
-
Feb 5th, 2003, 07:00 AM
#1
str_replace and <br> *resolved*
on page1.php, I have a <textarea>. The user can put in anything there, even new line characters. I want to use the str_replace function to replace any occurences of new line characters with "<br>"
How can I do this? (I'm guessing that vbCrlf isn't the correct one)
Last edited by mendhak; Feb 6th, 2003 at 06:07 AM.
-
Feb 5th, 2003, 05:47 PM
#2
Stuck in the 80s
I always do:
Code:
str_replace("\n", "<br>", $text);
But I've seen other people throw in combinationes of "\r\n"
-
Feb 5th, 2003, 07:44 PM
#3
Aha... \n. This seems so familiar 
I understand the \n must be newline. What is \r though?
-
Feb 5th, 2003, 07:48 PM
#4
Stuck in the 80s
Originally posted by mendhak
Aha... \n. This seems so familiar 
I understand the \n must be newline. What is \r though?
\r is a carriage return. There's also an nl2br() function:
string nl2br(string string)
Returns string with '<br />' inserted before all newlines.
-
Feb 6th, 2003, 02:35 AM
#5
-
Feb 6th, 2003, 06:15 AM
#6
Frenzied Member
Yeah I think you have to take into account that Linux, Mac and Windows all handle newlines differently, so just doing a str_replace won't always get it right (or at least that's my understanding of it).
-
Feb 6th, 2003, 03:53 PM
#7
Frenzied Member
that is correct.
\r = carrioage return and will work in windows
\n = newline and most of the time won't work in windows
\t = tab (I believe)
that is why most people use both.
-
Feb 6th, 2003, 09:31 PM
#8
Stuck in the 80s
Originally posted by phpman
\n = newline and most of the time won't work in windows
Wont work in Windows? I've never had a problem using newlines in Windows...
-
Feb 6th, 2003, 09:33 PM
#9
Frenzied Member
that is what I said.... most of the time it does, but that is why they add \r to it to make sure.
-
Feb 6th, 2003, 09:40 PM
#10
Stuck in the 80s
Originally posted by phpman
that is what I said.... most of the time it does
No you didn't...
Originally posted by phpman
most of the time won't work in windows
Is what you said.
-
Feb 6th, 2003, 10:21 PM
#11
Frenzied Member
actually it is for the headers where it messes up.
-
Feb 7th, 2003, 12:12 AM
#12
Stuck in the 80s
Originally posted by phpman
actually it is for the headers where it messes up.
Actually, my sack is in the back, I thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|