![]() |
BB Code
Hi,
Whats the best way of adding bb code to a variable? I've been playing about with a function using str_replace but I have also read that using preg_replace is more efficient and safer, is this true? Is there a better way I haven't heard of? |
I doubt it being more efficient for a simple BB parser. Safer, definitely, because with regex you can say if it doesn't have a closing tag then ignore it. That way you can ensure every single tag is closed and thus not affecting the rest of your website.
As for the answer, well, I'll let someone else answer that :) ! As I know they are typing as I type this. |
I think this is what you mean:
PHP Code:
|
Thanks for that :)
If I used the method above, how would I do things like: Code:
[ u r l=http://www.google.com]Google[/ u r l ] |
You do need to be able to understand preg pattern matching to be able to understand this, but something like:
PHP Code:
|
Thanks :)
I'll test it out now. |
Nope, I'm lost lol :(
What I have at the minute is: PHP Code:
I've tried: PHP Code:
|
How are you setting up the string you want to parse?
It should look like this I think PHP Code:
|
I've redone your regex and removed the
preg_quote.PHP Code:
|
The problem with bluesaga's function is that the patterns are fed into
preg_quote which renders them useless for your needs. An amended function could be something along the lines of: PHP Code:
|
Thats great, thanks a lot.
|
Lol, yea sorry i forgot to escape the patterns properly, got confused with the preg_quote....
|
| All times are GMT. The time now is 10:43 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0