MyBB Community Forums

Full Version: Help With $message processing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to fix a bug that I just found in a plugin of mine. THe custom table tag.

What I need to do is remove any newlines inbetween the table tags. THe reason I need to do this is because when mybb processes any posts it adds a <br> anywhere there is a newline. As a result when you use my table tag it has a bunch of html breaks that add lots of unwanted white space.

Here's an example of what I need to do,

[table]
[tr]
[td]data1[/td]
[/tr]
[/table]

[table]
[tr]
[td]data2[/td]
[/tr]
[/table]

needs to become

[table][tr][td]data1[/td][/tr][/table]

[table][tr][td]data2[/td][/tr][/table]

Does anyone have any ideas how to do this? I thought maybe I could use preg_replace but I'm not sure how that would work. I know how to get the text in between the [table] tags. For example,

$message = preg_replace("#\[table\](.*?)\[/table\]#si", "[table]$1[/table]" ,$message);

but I need to remove the newlines out of $1 at the same time. I already have a preg_replace that will remove newlines in the message. The problem of course is that I need to restrict it to removing newlines only between the [table] tags.

preg_replace( '/[\n\r]+/is', '', $message);

Any suggestions would be greatly appreciated.
That's kind of hard since you want any new lines within the td to be converted to a <br>. You'll probably have to break the string down or create a real parser.
You don't want to remove all the newline characters between the table tags. Someone might want to put a newline in their table cell. You want to remove the newlines between the BBCode

you might be able to use

$message = preg_replace("#\[table\]\n*\[tr\]\n*\[td\]#si", "[table][tr][td]" ,$message);
$message = preg_replace("#\[/td\]\n*\[/tr\]\n*\[/table\]#si", "[/td][/tr][/table]" ,$message);

I tried to find your plugin to download so I can see if you might be able to do this in one step but couldn't find it... is it available for download?
decswxaqz Wrote:I tried to find your plugin to download so I can see if you might be able to do this in one step but couldn't find it... is it available for download?
http://community.mybboard.net/showthread...7#pid30507
Okay I got it fixed thanks to Smetheads suggestion which is posted over on the mybb mods site. I'm uploading the updated version now for people to use.

You can get that in this thread

http://community.mybboard.net/showthread.php?tid=4849