BBCode and CSS Formatting

I want to store the content of a web site in the database, so I am using BBCode for the links, images, etc.

I need the following result:

<img class=“blockcenter” src = “elements/Canadian_Flag.jpg” alt=“Canadian_Flag.jpg” >
/* CSS centers the image */

from the BBCode:

I get:

<img src=" class=“blockcenter” photos/atackadstargetyoy.jpg" alt=“Canadian_Flag.jpg” />

So you see how it is mangled.

I am not sure if there is a solution in the PHP, I suspect it is in using something different for my CSS to center images. But it is close to midnight in Toronto and I am tired :slight_smile: I hope it is a quick spot and someone can get me going again.

Thanks
Stephen

in php there are functions for handling BBCode. there is a function BBCode_Create to create BBCode which returns a value that has to be used with the function bbcode_parse(<return value from bbcode_create>, ); this should return the required image tag.

Thank you. I saw that but didn’t quite understand it.

But I was able to find a CSS solution that is much easier. The content is within a div called middle.

#middle img { display: block; margin-left: auto; margin-right: auto }

bbcode is best used to simplify the code that the end user has to type to a bare minimum. Giving someone a bbcode that takes 3 attributes defeats the purpose of making it bbcode in the first place. If I were tackling this I’d make the bbcode simply

[flag]Canada[/flag]

And whatever definitions file deciphers the flag bbcode knows what the target image is, and what the alt text is (which should by the way be something like “Image of the National Flag of Canada” - not the filename - alt is for text readers, particularly those for the blind, so a filename is pointless as alt text.

Simpler still…

#middle img { display: block; margin: 0 auto; }

Or change the 0 to what you want the top and bottom margins to be.

I have failed to get this working.

The examples on the PHP manual site do not address getting the image file and alt value from within the pair.

for the purpose of getting image file and alt value from within the pair you need to use regular expression. If using php you can use for example preg_match(‘’,$data, $match); where $match[0] and $match[1] will give you the required value.