Jump to content

double quotes

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
Hello my friends, back again.

I've have a problem with my bb-code parsing again,


$QuoteLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">

<tr><td class="BBquotecodeheader"> '.$text['forum_BBquote'].'</td></tr>

<tr><td class="BBquotebody">$1</td></tr></table>';

preg_replace("/\[quote\](.+?)\[\/quote\]/is","$QuoteLayout", $post);

this is how I parse the quote-code.

now to my problem. how can I solve a correct parsing of double-quoting?


[ quote]I talk about what he wrote: 

[ quote]bla bla bla[/ quote]

And I think bla bla bla[/ quote]

will make the first [ quote] and first [/ quote]match, and the second [ quote]
won't be matched with the second [/ quote]

when the first quote should be matched with the last /quote and the inner ones with each other

anyone got a good idea how to possible parse this correct?

#2
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
What happens with your current code? I'm not entirely sure what's not working.

#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
He's saying that he's having problems with nested quotes. So if you add a second quote to the $post variable, it will be replaced. As for why I don't really know.

One of the more advanced PHP programmers will probably be able to help you. :)

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
why isn't difficult, as the preg_replace searches for the first [ quote] and the next coming [/ quote] and then matches them. the problem occurs if you have another [ quote] - [/ quote] pair in between these two tags, as it of course finds the inner [/ quote] first and don't match the right pairs

if anyone has an idea how to prevent this, it would be welcome....

#5
morefood2001

morefood2001

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,720 posts
The problem is inherited by using the same tags inside of each other. I have experienced this problem over and over again. When I was using my own parser, I would just define certain tags to change to avoid this, however it increased runtime drastically.

I now use the PEAR bbcode parser and that works great, I'm also sure it has a couple hundred more lines of code to prevent this :P

#6
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
[quote name='morefood2001']The problem is inherited by using the same tags inside of each other. I have experienced this problem over and over again. When I was using my own parser, I would just define certain tags to change to avoid this, however it increased runtime drastically.[/QUOTE]
I believe it. You could however, take advantage of preg_replace_callback and recursively replace the quotes creating an almost stack-like implementation. Not to mention php.net gives an example of preg_replace_callback using recursive structure to handle encapsulated BB code. But hey not everyone reads the php manual as much as I do, and I suppose [quote1], [quote2], and [quote3] work just as well. :P

[url=http://us.php.net/manual/en/function.preg-replace-callback.php]PHP: preg_replace_callback - Manual[/url]



#7
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
WOW! This is the power of CodeCall in a nutshell!

Thanks many times!

darn, I can't give you rep again atm, but you'll get it :-)

#8
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
No problem. I would give you a hand with your "unseen" posts issue, but I do not have any good solution to offer.