Reputation: 383
I want to remove all quotes from a string INCLUDE nested quotes.
it does not works for nested qoutes:
preg_replace("/\[quote(.*?)\](.*?)\[\/quote\]/i","", $text);
this works for something like:
[quote=admin]Welcome to RegExr 0.3b, an intuitive tool for learning, writing, and testing Regular Expressions. Key features include: [/quote]
but not for:
[quote=admin]Welcome to RegExr 0.3b, [quote] an intuitive tool for learning, [/quote] writing, and testing Regular Expressions. Key features include: [/quote]
would like to remove all qoute blocks
Upvotes: 0
Views: 223
Reputation: 169
/\[quote.*?\](.*?)\[\/quote\]((\s)*(\[\/quote])*)*/gis
It's working but it's not complete.
Note that after [/quote] there is next [/quote] and next and ... and there isn't anything else. This code remove all quotes that quoted but not multiple quotes like:
[quote] ... [quote]...[/quote] ... [quote]...[/quote] ... [/quote]
Upvotes: 1
Reputation: 5644
I think your mistake simply is the question mark in your expression.
Try preg_replace("/\[quote(.*?)\](.*)\[\/quote\]/i","", $text);
With your example posted in your edit:
$text = '[quote=admin]Welcome to RegExr 0.3b, [quote] an intuitive tool for learning, [/quote] writing, and testing Regular Expressions. Key features include: [/quote]';
$cleared = preg_replace("/\[quote(.*?)\](.*)\[\/quote\]/i","", $text);
var_dump($cleared);
// -> string(0) ""
Upvotes: 1
Reputation: 1412
Why not str_replace('"', '', $string);
?
Edit: this is wrong answer. I've misread the question.
Upvotes: -1