BBCODE (7)

1 Name: #!/usr/bin/anonymous : 2009-11-19 23:49 ID:Qv5znUI0

okay, so I have this php custom tag parser. It uses regular expressions. Here's part of the code:

$bbcode = array('#\[sup\](.*?)\[/sup\]#si' => '\\1');
$text = preg_replace(array_keys($bbcode), array_values($bbcode), $text);

It works fine. If I set $text = "[sup]superscript[/sup]" it changes it to superscript.

However, if I set $text = "[sup]i[sup]i[/sup][/sup]" which uses multiple superscript tags in one group, it changes it to i[sup]i[/sup].

Any ideas on how i could fix that?

2 Name: #!/usr/bin/anonymous : 2009-11-20 19:43 ID:Heaven

Don't use regexps for parsing. Ever.

Read this: http://kore-nordmann.de/blog/do_NOT_parse_using_regexp.html

(Never mind that bbcode is phenomenally retarded in the first place)

3 Name: #!/usr/bin/anonymous : 2009-11-21 06:51 ID:xk8dw1AY

Well wtf do I use?

4 Name: #!/usr/bin/anonymous : 2009-11-21 10:18 ID:Heaven

I'm going to suggest the obvious: search for php bbcode. If you were using perl, you'd search perl bbcode instead; if you wanted to implement html, you'd search languageX html.

5 Name: #!/usr/bin/anonymous : 2009-11-21 17:27 ID:/bQQ4jwn

use str_replace() and move on with your life.

6 Name: #!/usr/bin/anonymous : 2009-11-24 04:10 ID:Heaven

>>5
Way to entirely miss the point.

I was wrong to try to talk to PHP programmers. I'll be leaving now for smarter threads.

7 Name: #!/usr/bin/anonymous : 2009-11-26 23:20 ID:Heaven

I would suggest using a well known PHP BBCode parser?
http://pecl.php.net/package/bbcode
This thread has been closed. You cannot post in this thread any longer.