删除bbcode之间的所有空格

I'm trying to remove all whitespaces between:

[code/][code]

For example:

[code]http://stackoverflow.com/questions/ask[/code]


[code]http://stackoverflow.com/questions/ask[/code]
lorem ipsum
[code]http://stackoverflow.com/questions/ask[/code]

I want to get:

[code]http://stackoverflow.com/questions/ask[/code]
[code]http://stackoverflow.com/questions/ask[/code]
lorem ipsum
[code]http://stackoverflow.com/questions/ask[/code]

My code:

$string = preg_replace('@\[code\]\[(s+)\]\[\/code\]@si', '', $string);

Do you just mean spaces or all whitespace?

For just spaces, use str_replace:

$string = str_replace(' ', '', $string);

For all whitespace, use preg_replace:

$string = preg_replace('/\s+/', '', $string);

You could do something like this, using a regex and preg_replace():

$text = preg_replace('/\[(.*?)\]\s*\[/', '[\1][', $text);