|
-
Sep 16th, 2002, 02:49 PM
#1
Thread Starter
Frenzied Member
nl2br
Everytime I use nl2br() it seems to replace every new lines with 2 <br /> tags. Does this happen to everyone or is it just me?!
-
Sep 16th, 2002, 05:25 PM
#2
Stuck in the 80s
Why not?:
Code:
$string = str_replace('\n', '<br>\n', $string);
-
Sep 16th, 2002, 11:01 PM
#3
Fanatic Member
I have never had that problem. What version of PHP are you running?
Also a more correct statement to hobo's response is the following:
$string = preg_replace("/(\n\r|\r|\n)/isu","<br />",$string);
-
Sep 17th, 2002, 05:20 AM
#4
Thread Starter
Frenzied Member
Alright, thanks for the responses. I have already tried what you said Hobo and it seems to do the same things. I'll try cpradio's suggestion today, but I assume it's something to do with my code as no-one else has the problem. And my host is using version 4.2.2, and the same thing happened when they had an earlier version.
-
Sep 17th, 2002, 10:51 AM
#5
Thread Starter
Frenzied Member
I tested cpradio's sugesstion and it was the same, but I'm using the following as a workaround, if anyone has any better ideas let me know:
Code:
$string = preg_replace("/(<br \/><br \/>)/isu","<br />", preg_replace("/(\n\r|\r|\n)/isu","<br />",$string));
-
Sep 17th, 2002, 12:13 PM
#6
Frenzied Member
you can try it this way
$string= ereg_replace("(\r\n|\n|\r)", "<br />", $string);
no need to have isu in there.
-
Sep 17th, 2002, 03:15 PM
#7
Fanatic Member
true, the isu isnt needed, i just didnt want to take it out of the template I pulled it from, guess im just too lazy
-
Sep 17th, 2002, 03:44 PM
#8
Thread Starter
Frenzied Member
Thanks, I did figure I could take it out. My friend suggested that I should turn all \r\n into newlines to fix windows, and replace \r with \n to fix Macs then use nl2br, so I'll try that (when my servers stops being a cry baby and starts working again )
-
Sep 17th, 2002, 03:47 PM
#9
Fanatic Member
The code that I and phpman posted does just that. It converts windows line endings to <br /> and Macs to <br />
-
Sep 18th, 2002, 04:23 AM
#10
Thread Starter
Frenzied Member
Oh yeah right, why didn't I notice that?
-
Sep 30th, 2002, 05:34 PM
#11
Lively Member
My host's PHP also does the double <br> with nl2br() as well. Thanks for the workaround, its really useful!
-
Oct 1st, 2002, 04:48 AM
#12
Thread Starter
Frenzied Member
So at least I'm not alone Must be a dodgy setup or something.
-
Oct 9th, 2002, 02:13 PM
#13
Thread Starter
Frenzied Member
I think I figured out why I was getting to <br />s. It was because I had an implode("\n", $string), then I was using nltbr on it. I think I should have had an empty string first the glue/first argument. Would that have been the cause?
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
|