Regex & BBCode - Perfect Nested Quote

I am working on some BBcode for my site.

I managed to get most of the codes working perfectly, however the [QUOTE] tag gives me some grief.

When I get something like this:

[QUOTE=1]
[QUOTE=2]
This is a quote from someone else
[/QUOTE]
This is someone else quoting someone else
[/QUOTE]

He will return:

> 1 said:  [QUOTE=2]This is a quote from
> someone else

This is someone else quoting someone else[/QUOTE]

So what happens, [/ quote] closes the block of quotes from the enclosed quote.

I am using regex:

"[quote=(.*?)\](.*?)\[/quote\]'is"

How can I make it nested? Will the quotes be displayed correctly?

Thank.

+3
source share
2 answers

You can create a recursive regular expression (available with libpcre-3.0 according to their change):

\[quote=(.*?)\](((?R)|.)*?)\[\/quote\]

But it would be better if you follow @codeka's advice.

Update: (?R) " , (?R)". , a(?R)?b ( ) a(a(?-1)?b)?b, a(a(a(?-1)?b)?b)?b . (?R) (?N), (?+N), (?-N) (?&a), " N- ", " N- ", " N" "" "a" ".

+2

, . HTML , , ...

, , - preg_split, . , , :

  • [QUOTE = 1]
  • ()
  • [QUOTE = 1]
  • - .
  • [/QUOTE]
  • - , -
  • [/QUOTE]

, HTML . "", , "[/quote]", , , HTML. , , , HTMLPurify - .

0

Source: https://habr.com/ru/post/1747105/


All Articles