Page 1 of 2

BB Code.. Next

Posted: Fri Jan 09, 2004 2:05 pm
by Dale
I have a file (inc/bbcode.php) now how do i allow it to happen, the bb code replace to the result?

Posted: Fri Jan 09, 2004 8:16 pm
by Nay
Ur, maybe have the process of implementing the bbcode as a function or method then include the file then () it (Call it)?

O.o

-Nay

Posted: Fri Jan 09, 2004 9:15 pm
by m3mn0n
You might want to reword the question. What exactally do you want, and what problems are you having getting to this goal?

Posted: Sat Jan 10, 2004 2:36 am
by Dale
I have created a file (called bbcode.php which is in a directory called inc)
Now i want to know what do i do now as i've created this file, do i include it in the post.php thread or in the header of every page?

Posted: Sat Jan 10, 2004 2:39 am
by Nay
If you were making any less sense I'd tell you to include it where you want to actually 'use' it O.o

-Nay

Posted: Sat Jan 10, 2004 2:40 am
by Dale
So (in a phpBB forum example) i'd include it in the header of viewtopic.php.

Posted: Sat Jan 10, 2004 5:47 pm
by Gen-ik
First of all you might want to get rid of your address from your profile otherwise you'll end up with dead hampsters and human limbs being sent to you (there are some strange people on this forum).

Anyway... on to your question. It depends on what your BBcode page contains, is it a function() or is it a class()?

Posted: Sat Jan 10, 2004 6:02 pm
by d3ad1ysp0rk
Gen-ik wrote:First of all you might want to get rid of your address from your profile otherwise you'll end up with dead hampsters and human limbs being sent to you (there are some strange people on this forum).
or <span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>..

Posted: Sat Jan 10, 2004 6:11 pm
by Dale
LiLpunkSkateR wrote:or <span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>..
Bring it on ;)

Posted: Sat Jan 10, 2004 6:27 pm
by Dale
Oh... im using a replace command erm i'll try and find it (i've got it on my computer upstairs which is groany and noisy and will wake everyone up in the house... stupid floorboards... and stupid timezone)

Posted: Sat Jan 10, 2004 9:09 pm
by Gen-ik
Ok this is how I would normally add BBCode functions to a page.

First of all (like you have done) I create a single fill which contains the BBcode function... let's call it myBBcode.php for now.

This is an example of what myBBcode.php might contain...

Code: Select all

<?php

function BBCode($string)
{
    $f[] = "\(b\)([^\(]+)\(/b\)";
    $t[] = "<b>\\1</b>";

    $f[] = "\(u\)([^\(]+)\(/u\)";
    $t[] = "<u>\\1</u>";

    foreach($f as $key => $value)
    {
        $string = eregi_replace($value, $t[$key], $string);
    }

    return $string;
}
?>
As you can see I'm using eregi() here but the same principle applies to anything you want to use.

Now in the page where you think you might want to use BBCode you load your myBBcode.php file (near the top is always good)... and then you can use the BBCode function() whenever you need to.

Code: Select all

<?php require_once("inc/myBBcode.php"); ?>

<html>
<head>
</head>
<body>

<?php

$someText = "Blablabla this should be (b)bold(/b) text...";

$converted = BBcode($someText); // This will use the BBCode function() to convert any BBCode in $someText and then put it into the $converted variable.

echo $converted;

?>

</body>
</html>

Hope that makes sense :)

Posted: Sun Jan 11, 2004 3:34 am
by Dale
Yep thanks ;)

Posted: Sun Jan 11, 2004 4:46 am
by Nay
Dale wrote:
LiLpunkSkateR wrote:or <span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>..
Bring it on ;)
You can PM Jason for that ;)

I'm sure he has some of his Christmas gift left...

-Nay

Posted: Sun Jan 11, 2004 4:48 am
by Dale
I dont think i would need it.. im 16 at the moment.. so whens my sexual peak????

Posted: Sun Jan 11, 2004 4:52 am
by Nay
mMm, dang, I wasted my 800th post on some useless advertisment.

Ah actually I gave you a link to paradise B), Jason must have edited my post to that <_<.

-Nay