| |||
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 |
| ||
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 |
| ||
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)) |
Zem |
| ||
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 |
| ||
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 |
|
Xkeeper |
| ||
Level: 105 Posts: 596/2846 EXP: 12030786 Next: 231474 Since: 02-19-07 Last post: 6062 days Last view: 2800 days |
Posted by blackhole89That'd still break tables, which have the same problem. Kind of. I 'unno. ____________________ I dealt with it. |
Cellar Dweller |
| ||
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 |
| ||
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 |
| ||
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 ex |
Zem |
| ||
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 HEY, GOOD IDEA ! Posted by stag019 Posted by Xkeeper 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 |
| ||
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 |
© 2005-2023 Acmlm, blackhole89, Xkeeper et al. |
MySQL - queries: 67, rows: 85/86, time: 0.016 seconds. |