If I understood correctly, then you probably want something like this:
$firstTag = strpos($content, "[q]"); $lastTag = strrpos($content, "[/q]", 0); $secondTag = strpos($content, "[q]", $firstTag + strlen("[q]")); $secondLastTag = strrpos(substr($content, 0, $lastTag), "[/q]"); $content = substr_replace($content, "", $secondTag, $secondLastTag - $secondTag + strlen("[q]") + 1);
I apologize for any errors, I do not have a PHP interpreter with which to test, and it has been about 9 months since I used it, so I'm a little rusty.
Effectively, what we are trying to do, we first find the position in the line of the first opening tag, and we find the position of the last closing tag. After we have these positions, we can use them as offsets to start the search to find the second opening tag and the second last closing tag. Once we know their positions, we then use substr_replace to replace all the text in the content line, starting from the second opening tag, to the second last closing tag with an empty string.
So, to illustrate, if we have:
[q] [q] Internal 3 [q] Internal 2 [/ q] Internal 1 [/ q] External [/ q]
we will find the second tag [q], the second last tag [/ q] and replace them and everything in between with an empty string and get:
[Q] External [/ Q]
Is this what you were looking for?