I have nested quotes enabled in my private message system, but now I want to show the user a part of the message when they hover the title of the message.
To get the relevant text out of the message I want to delete the quote parts.
The quote structure is as follows:
[quote]
[quote]
dasdasa adsadsa ds a
[/quote]
ddasd asd ads adsasd
[/quote]
How can I remove everything between de quote tags?
I have tried it with the following code, but the last part of the nested quotes won't remove:
while(preg_match('#\[quote=(.*?)\](.*?)\[\/quote\]#si', $message)) {
$message = preg_replace('#\[quote=(.*?)\](.*?)\[\/quote\]#si', '', $message, 1);
}
while(preg_match('#\[quote\](.*?)\[\/quote\]#si', $message)) {
$message = preg_replace('#\[quote\](.*?)\[\/quote\]#si', '', $mess开发者_运维问答age, 1);
}
Any suggestions how to delete these quotes out of the message? Thx!
a) better not use regex...
b) use recursion.
#\[quote](?:(?>[^[])|\[(?!/?quote])|(?R))*\[/quote]#
I haven't tested the pcre, but it should do.
There is no need to call preg_match()
, and then call preg_replace()
, when preg_replace()
can replaces all strings matching the regular expression with a single call.
The problem with the regular expression you are using is that the code you reported would produce the following output:
ddasd asd ads adsasd
[/quote]
精彩评论