Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,498,885
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 04-29-24 02:39 AM
Guest: Register | Login

0 users currently in Help/Suggestions/Bug Reports | 2 guests

Main - Help/Suggestions/Bug Reports - here's how to stop newlines from doubling in pre tags New thread | New reply


Zem
Posted on 03-07-07 12:32 AM Link | Quote | ID: 11417


Panser
DOOM FOR VON DOOM
Level: 42

Posts: 31/343
EXP: 503254
Next: 18108

Since: 02-21-07

Last post: 5516 days
Last view: 5514 days
put
pre br { display: none; }
in some css file that thread pages use
this is easier than trying to only nl2br() outside of <pre> tags

____________________
 

stag019
Posted on 03-07-07 01:16 AM Link | Quote | ID: 11449


Snifit
Level: 40

Posts: 23/299
EXP: 409682
Next: 31627

Since: 02-19-07

Last post: 4283 days
Last view: 2169 days
Yeah, but it would still be beneficial to know how to not nl2br() inside tags, because even though you can do that for things like <pre>, <style> tags still break because of <br>s.
Something along the lines of this would help:
while(preg_match("@<style[^>]*?>.*?<br>.*?</style>@si", $msg, $matches))

$msg=str_replace($matches[0], preg_replace("@<br>@si", "", $matches[0]), $msg);

Zem
Posted on 03-07-07 01:43 AM Link | Quote | ID: 11455


Panser
DOOM FOR VON DOOM
Level: 42

Posts: 32/343
EXP: 503254
Next: 18108

Since: 02-21-07

Last post: 5516 days
Last view: 5514 days
hmm, but that would remove any instances of <br> that the user intentionally put there for whatever reason (which shouldn't come up in <style> tags, but might come up in <pre> tags, or maybe some other tags where we wouldn't want to nl2br()).

maybe it would be best to try to separate out the post into separate strings, based on what parts are inside specific tags where we don't want to add <br> and what parts aren't, then nl2br() the parts outside those tags, then merge them together again. that would take a bit of work, but shouldn't take too long to figure out. I could give it a try.

but the solution in the OP works as a quick fix to a more specific and common problem.

____________________
 

blackhole89
Posted on 03-07-07 04:18 PM Link | Quote | ID: 11794


The Guardian
Moloch whose eyes are a thousand blind windows!
Level: 124

Posts: 96/4196
EXP: 21537497
Next: 299104

Since: 02-19-07
From: Ithaca, NY, US

Last post: 474 days
Last view: 86 days



Or we could make it so newlines get replaced with
instead with
\n by the formatting code.

____________________



Xkeeper
Posted on 03-08-07 02:28 AM Link | Quote | ID: 11972


Level: 105

Posts: 596/2846
EXP: 12030786
Next: 231474

Since: 02-19-07

Last post: 6062 days
Last view: 2800 days
Posted by blackhole89
Or we could make it so newlines get replaced with
instead with
\n by the formatting code.
That'd still break tables, which have the same problem. Kind of.

I 'unno.

____________________
I dealt with it.

Cellar Dweller
Posted on 03-09-07 03:25 AM Link | Quote | ID: 12466


Snifit
Level: 39

Posts: 11/287
EXP: 385268
Next: 19503

Since: 02-19-07
From: Arkansas

Last post: 4054 days
Last view: 3222 days
I second blackhole98's suggestion. In fact, if he had not suggested it, I would have suggested it myself.

How would that break anything?

Xkeeper
Posted on 03-09-07 03:29 AM Link | Quote | ID: 12467


Level: 105

Posts: 637/2846
EXP: 12030786
Next: 231474

Since: 02-19-07

Last post: 6062 days
Last view: 2800 days
Things like
<table>
<tr>
etc.

would still be ruined, and it'd make the HTML internally a mess. Not to mention editing posts via PHPMyAdmin would be hell.

Just making a way for some tags to not get nl2br'd would be nice...

____________________
I dealt with it.

Spikeman
Posted on 03-09-07 04:36 AM Link | Quote | ID: 12491


Red Koopa
Pathetic excuse for a hacker
Level: 28

Posts: 27/132
EXP: 120169
Next: 11169

Since: 02-19-07

Last post: 6226 days
Last view: 6225 days
I'd recommend using some form of regular expression.

Zem
Posted on 03-13-07 02:37 AM (rev. 5 of 03-13-07 04:12 AM) Link | Quote | ID: 14531


Panser
DOOM FOR VON DOOM
Level: 42

Posts: 44/343
EXP: 503254
Next: 18108

Since: 02-21-07

Last post: 5516 days
Last view: 5514 days
Posted by Spikeman
I'd recommend using some form of regular expression.

HEY, GOOD IDEA !

Posted by stag019
Yeah, but it would still be beneficial to know how to not nl2br() inside tags,


Posted by Xkeeper
Just making a way for some tags to not get nl2br'd would be nice...


hey look what I made

try it out! I tested it pretty well, but maybe there's some weird cases I didn't think of. it'll probably behave unexpectedly with improperly overlapping tags, but the worst it could do is put
inside one region of one of them, which is not the biggest of your problems if you've got overlapping tags anyway.

edit: okay, fixed
edit: it has been pointed out that this implementation won't work for tables. I might come up with something for that later.

____________________
 

Zem
Posted on 03-14-07 04:43 AM Link | Quote | ID: 14941


Panser
DOOM FOR VON DOOM
Level: 42

Posts: 45/343
EXP: 503254
Next: 18108

Since: 02-21-07

Last post: 5516 days
Last view: 5514 days
update!

this code produces this output. (the txt file is just the php file, saved as .txt.)

KNOWN ISSUE: this will NOT work with NESTED TABLES - it will behave erratically, possibly breaking up the string around mismatched <td> </td> pairs. this will only come up in the case of bad html, or if a table is INSIDE a table cell, which is almost never useful. the worst possible result is that <br> tags are not inserted in places where they should be and are inserted in places where they shouldn't be. it won't screw up good html. again, this will only come up if there is a table inside another table.

the other tags (<pre> and <style>) work just fine, inside or outside table cells. if you'd like to add more tags, add them to the end of the $tagorder array, following the pattern of the others. if you don't want xhtml-style <br> tags, change the nl2br() line near the bottom to a str_replace or whatever.

____________________
 

Main - Help/Suggestions/Bug Reports - here's how to stop newlines from doubling in pre tags New thread | New reply

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.024 seconds. (321KB of memory used)
MySQL - queries: 67, rows: 85/86, time: 0.016 seconds.