This Message Forum is no longer in use

Please use the new Bravenet Help Forums FOUND HERE

General Forum
This Forum is Locked
Author
Comment
how do i add bbcode

how do i add bbcode to my forum
http://ogameforums.comuv.com/

like

Code:
[img] <a href=" smilies [font] [color]" target="_blank"> smilies [font] [color]</a>


like those

Browser: IE 7

Re: how do i add bbcode

just to be more clear i have this code but i cant get it to work if i try to post something

Code:

<?php

function bbcode($input){
$input = strip_tags($input);
$input = htmlentities($input);

$search = array(
'/<span style="font-weight:bold;">(.*?)</span>/is',
'/<span style="font-style:italic;">(.*?)</span>/is',
'/<span style="text-decoration:underline;">(.*?)</span>/is',
'/<img src="(.*?)">/is',
'/<a href="(.*?)" target="_blank">(.*?)</a>/is',
'/[font color=(.*?) size=(.*?) face=(.*?)](.*?)/is',
'/[h1](.*?)[/h1]/is',
'/[special](.*?)[/hat]/is'
);

$replace = array(
'<b>$1</b>',
'<i>$1</i>',
'<u>$1</u>',
'<img src="$1">',
'<a href="$1">$2</a>',
'<font style="color:$1;font-size:$2;font-face:$3">$4</font>',
'<h1>$1</h1>',
'<a href="http://google.com" style="font-size:32pt;text-decoration:blink;color:#FF0099">$1</a>'
);

return preg_replace($search,$replace,$input);
}

?>
[/font]

i can get it to work if i do this but i want it to work if someone does a post

Code:

$var = "<a href="http://gamecrasyfreak.bravehost.com/" target="_blank">g</a>";
echo bbcode($var);

Browser: IE 7

Re: how do i add bbcode

the bravenet forum stripped a lot out of my code

Browser: IE 7

Re: how do i add bbcode

There are two ways to do this. The first is to take a post and convert it from bbcode into html before entering it into the database. The second is to store the bbcode in the database. The second way is to store the bbcode in the database and convert it before it is displayed each time. The first way is by far the easiest since it just requires one function call.

Also, if you've compiled php with the bbcode module, check out the inbuilt functions http://php.net/manual/en/book.bbcode.php

Browser: Mozilla Firefox 3.6.*

OS: Windows 7

Re: how do i add bbcode

how do i do the first function?

Browser: IE 7

Re: how do i add bbcode

Assuming the textarea (where the post is written) has the name "txt_post". Yours is probably named differently.

On the page that deals with inserting the post into the database you'd need something like this:

$the_post = $_POST['txt_post'];
$the_post = bbcode($the_post);

/* Now when you insert the values into the database use $the_post for the post content /*

If you don't know much about PHP then something as complex as a forum can be dangerous, especially if you didn't write the code yourself.
I would suggest you go and find some PHP tutorials, and when you have enough knowledge to write a forum then you're in a much better position to make sure the code is safe to use.

Browser: Mozilla Firefox 3.6.*

OS: Windows 7

Re: how do i add bbcode

i dont know why this wont work but it wont it just keeps saying you didn't insert a post when i did

Browser: IE 7

Re: how do i add bbcode

this is my code
http://ogameforums.comuv.com/thephpcode.zip

Browser: IE 7

Re: how do i add bbcode

Your error comes from these two lines:
$yourpost = $_POST['txt_post'];
$yourpost = bbcode($the_post);
Notice that the variable containing the post is $yourpost, but the one you're trying to bbcode is $the_post. Since $the_post is not set anywhere it counts as an empty string. Just change $the_post to $yourpost and it should work.

Browser: Mozilla Firefox 3.6.*

OS: Windows 7

Re: how do i add bbcode

Thanks for the help

Browser: IE7

Re: how do i add bbcode

ok to get it to work i had to get rid of strip tags is there a way to get it to work were people can still use [ these ] those but still get rid of html code?

Browser: IE 7

Re: how do i add bbcode

I wouldn't have thought that strip_tags would strip bbcode, but you could try replacing it with htmlspecialchars() instead. Only problem with that is someone could probably insert on click events etc. into the bbcode tags and they wouldn't get removed, allowing users to run whatever javascript they wanted. Twitter had a lot of problems with this recently.

Browser: Mozilla Firefox 3.6.*

OS: Windows 7