Forum Moderators: coopster

Message Too Old, No Replies

How do I parse UBB code?

         

The Cricketer

3:05 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



I'm looking to insert a number of images throughout my web site articles which will reside in a MySQL database.

Because I don't want to put <img src=""> code in my database I am thinking of using UBB code to reference my images. This will hopefully give me more leeway in the future if image tags change, for example like <img src=""> to <img src="" /> have done. i.e. I won't have to go through my database changing entries.

However I don't know much about ubb code and how to put it into the database and how PHP should parse it to display the html when it comes out the other side.

I'm slightly confused about where to find information about how to do the above.
Should I be reading up on regular expressions?

dreamcatcher

5:31 pm on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

Try looking into eregi_replace & quotemeta for starters. Here`s an example of how you might use them to parse img tags:

$text = eregi_replace("\\[img\\]([^\\[]*)\\[/img\\]", "<img src=\"\\1\" border=\"0\">", $text);

Hope that helps.

The Cricketer

7:40 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



Thanks a lot I'm starting to get there now.
Has anyone got any views of using UBB code in a database? Is it a good idea as opposed to HTML tags?

I'm building a small CMS where currently I am the only user, but I suppose in the future when there are more users then it could be easier for the 'uneducated' to use this UBB code?

dreamcatcher

8:35 pm on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Its a lot easier and if you are going to have people input data, more secure when you can control how tags are formatted. Especially if you are sending data to a database.