Log in

View Full Version : BB Code?



MrCraig
15-10-2007, 10:52 AM
Ok, im wanting to do something with bb code..

Would the PHP for it be like...


<?php

if(preg_match("
",$body) && preg_match("",$body))
{
preg_replace("
","<div align=\"center\">");
preg_replace("","</div>");
}
?>

Tomm
15-10-2007, 03:04 PM
You don't do it like that. It will slow down the script and you are calling uncessery functions. Also preg_replace returns a value and does not automatically update the source value.

Example:



$value = preg_replace('#\[b\](.*?)\[/b\]#i','<strong>$1</strong>',$value);

MrCraig
16-10-2007, 11:36 AM
Ty =]

Does anyone know what the PHP would be for


Hi There


And what would the javascript be for inserting the tags into the textarea? (Called privmsg)

LegendOfNoob
16-10-2007, 02:32 PM
hmm well i would search
PHP Font Attributes Tutorial

however you may also find this HTML to bbCode Converter it also translates to other forum codes

http://www.seabreezecomputers.com/html2bbcode/

MrCraig
17-10-2007, 07:06 PM
Erm.. I dont need to know how to translate forum codes..

RichardKnox
17-10-2007, 07:45 PM
Use str_replace

Eg:



$string = str_replace("[font=", "<font=", $string);

Tomm
17-10-2007, 08:37 PM
Bad idea because you can get unclosed tags.


Use str_replace

Eg:



$string = str_replace("[font=", "<font=", $string);

Assassinator
18-10-2007, 08:24 AM
On your page have


<?php
session_start();
include_once "FILENAMEHERE.php"; ?>

Then in FILENAMEHERE.php..


<?
function replace($txt) {
$txt = str_replace(":D", "HTML Here", $txt);
$txt = str_replace("BB Code Here";
}
?>

And it you want to add two or three


<?
function replace($txt) {
$txt = str_replace(":D", "HTML Here", $txt);
$txt = str_replace("BB Code Here", $txt = str_replace(":D", "HTML Here", $txt);
$txt = str_replace("BB Code Here";
}
?>

QuickScriptz
18-10-2007, 11:30 AM
Well personally I would just use an array....

<?php
$find = array('', '', '', '');
$rep = array('<u>', '</u>', '<b>', </b>');
$replace = str_replace($find, $replace);
?>

Tomm
18-10-2007, 02:55 PM
I would highly recommend you don't do any of the above and stick with regular expressions using preg_replace. If you want to use arrays, preg_replace also supports indexed arrays.

MrCraig
18-10-2007, 03:15 PM
Ok, ive doen what tom said to do first,

But does anyone know how to make like



something


?

Want to hide these adverts? Register an account for free!