0

I am making plugin for forum that delete over-quoting, so that there are only one level quotes:

<quote>
    <quote>subquote</quote>
    quote111
</quote>
text
<quote>quote222</quote>
text

<quote>subquote</quote> should be removed, because it is in another quote.

What is the best way to do it? I thought that this is widespread, but I cannot google it out.

It should be some crazy regexp. I can't wrap my head around this.

Qiao
  • 16,565
  • 29
  • 90
  • 117

2 Answers2

0

If you have XML then use it to loop at every <quote>.

When you have it in loop you can use strip_tags() to remove subquotes.

You can use SimpleXML for that.

There's no need to use "crazy regexp"

This link shows how to remove item with specific attribiute you can use it to fit your needs.

Community
  • 1
  • 1
Robert
  • 19,800
  • 5
  • 55
  • 85
  • It is bbcode, i just change `[]` to `<>` while testing, so not to escape them. But yes, xml could be the way. – Qiao Jul 11 '13 at 13:16
0

I just did it with regexp, the easy way. Using negative lookeahead solved problem.

while ( preg_match("|<quote>((?!</quote>).)*?<quote>|us", $text) )
    $text = preg_replace("@(<quote>(?(?!quote>).)*?)<quote>(?(?!quote>).)*?</quote>@us", "$1", $text);

It checks if any subquotes left and remove one subquote in a time.

Qiao
  • 16,565
  • 29
  • 90
  • 117