0

我想从包含嵌套引号的字符串中删除所有引号。

它不适用于嵌套的 qoutes:

preg_replace("/\[quote(.*?)\](.*?)\[\/quote\]/i","", $text);

这适用于:

[quote=admin]Welcome to RegExr 0.3b, an intuitive tool for learning, writing, and testing Regular Expressions. Key features include: [/quote]

但不适用于:

[quote=admin]Welcome to RegExr 0.3b, [quote] an intuitive tool for learning, [/quote] writing, and testing Regular Expressions. Key features include: [/quote]

想删除所有 qoute 块

4

3 回答 3

1

我认为你的错误只是你表达中的问号。

尝试preg_replace("/\[quote(.*?)\](.*)\[\/quote\]/i","", $text);

在您的编辑中发布您的示例:

$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) ""
于 2012-09-15T09:24:07.513 回答
1
/\[quote.*?\](.*?)\[\/quote\]((\s)*(\[\/quote])*)*/gis

它正在工作,但它并不完整。

请注意,在 [/quote] 之后有下一个 [/quote] 和下一个和 ...,没有其他任何内容。此代码删除所有引用但不包含多个引号的引号,例如:

[quote] ... [quote]...[/quote] ... [quote]...[/quote] ... [/quote]
于 2013-08-20T18:09:42.780 回答
-1

为什么不str_replace('"', '', $string);呢?

编辑:这是错误的答案。我误读了这个问题。

于 2012-09-15T09:18:37.290 回答