...

View Full Version : BBCode



Wanna
09-14-2011, 11:23 AM
Hi,

Does somebody has a BBCode function for me?

And then i mean, not for 1 code, but for a few.

Like:


$string = "

Testing[Nice text";


And that it excecute all the bbcode

And also like this site, that text inside a php/code tag won't be transformed
Hope you can help me with this.

BluePanther
09-14-2011, 11:59 AM
This forum isn't for us to give you code, it's to aid your learning and give you advice to solve problems.

However, I will give you some example logic. You want to set up a set of rules, i.e. for this do this, and set up a preg_replace or str_replace to replace segments with your desired rule. It might be easier if you use recursion for this as well.

Wanna
09-14-2011, 12:07 PM
How could i make a recursion for the rule in the first rule then?
Checking howmuch tags there's in a rule, and then loop that many trough a function?

BluePanther
09-14-2011, 12:14 PM
I think you're misunderstanding the concept of recursion. I'm not sure you even need it tbh. I'm sure you could define two arrays, one with patterns to find and one with patterns to replace with. Then, use preg_replace once to replace all your bbcode with your rules.

Would have to get confirmation on how that works though. I've seen it done similar to that, but not entirely confident on it as I hardly ever use preg_replace.

Wanna
09-14-2011, 12:20 PM
If workerd with preg_match before, and kind of created this already once.
But only the quote workerd for the first time, and not the quote inside quote would be quoted :P

BluePanther
09-14-2011, 12:22 PM
Maybe that's where recursion comes in, with some sort of combination of preg_match to make sure you catch the stragglers :P

Wanna
09-14-2011, 12:55 PM
I think i got it now ;)
Thanks

BluePanther
09-14-2011, 01:06 PM
No problem



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum