2005-12-11, 03:53 AM
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,
needs to become
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,
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.
Any suggestions would be greatly appreciated.
btw I love the smilies hehe
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.
btw I love the smilies hehe