Help needed getting rid of newlines
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,

$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
Maybe you should try this?
$message = preg_replace("#\[table\](.*?)[\n\r]+(.*?)\[/table\]#si", "[table]$1$2[/table]" ,$message);
I'm not sure if it'll work. But otherwise, use a function to clear them out.
$message = preg_replace("#\[table\](.*?)\[/table\]#esi", "clearnewlines(\"$1\")" ,$message);
And the you have to add this in your plugin file:
function clearoutnewlines($message)
$message = preg_replace( '/[\n\r]+/is', '', $message);
$message = "[table]".$message."[/table]";
return $message;
Or something like that. Just test around a bit.

Forum Jump:

Users browsing this thread: 1 Guest(s)