Forum Moderators: coopster

Message Too Old, No Replies

Special/Unusual BBCode. Any ideas?

Special/Unusual BBCode. Any ideas?

         

Fourjays

5:16 pm on Jul 12, 2006 (gmt 0)

10+ Year Member



Hi,
On my current project, I am going to have a BBCode parser for comments, forum posts, etc.

I have the basic, normal BBCode working fine. However I would like to do a couple of special BBCode tags specific for my website. All of these special tags follow the same basis; [tag]content[/tag]

I want to read the content between the [tag]'s and then use the content in a MySQL database query. As an example; [siteimg]Awesome Picture[/siteimg]. It takes "Awesome Picture" and queries the database for the physical location of the image called "Awesome Picture" and then displays "Awesome Picture Thumb" with a link to "Awesome Picture".

I managed to get it going in several different ways, but none worked quite right. Using it on a "comments" page it was parsing them fine on individual comments providing there was only one image per comment. If there was more than one, it would display the same image repeated. When I eventually managed to get it displaying the images individually (using an echo within the function), all other content within the comment was wiped out.

Can anyone advise me on how I would accomplish this successfully?
Thanks

coopster

4:47 pm on Jul 13, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How about using a preg_replace_callback() [php.net] to match and return the specific-image code for each? Within the callback routine you would perform your query and setup the value to be returned.

Fourjays

9:52 pm on Jul 13, 2006 (gmt 0)

10+ Year Member



That looks like what I'm after. Will let you know how it goes. Thanks.

Fourjays

10:15 pm on Jul 14, 2006 (gmt 0)

10+ Year Member



Worked a treat. Thanks alot for your help.

coopster

1:17 am on Jul 15, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I love PHP's callback functions. Glad to know it worked out for you ;)