BB Code.. Next

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

BB Code.. Next

Post by Dale »

I have a file (inc/bbcode.php) now how do i allow it to happen, the bb code replace to the result?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

You might want to reword the question. What exactally do you want, and what problems are you having getting to this goal?
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

So (in a phpBB forum example) i'd include it in the header of viewtopic.php.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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()?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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>..
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

LiLpunkSkateR wrote:or <span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>..
Bring it on ;)
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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)
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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 :)
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Yep thanks ;)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

I dont think i would need it.. im 16 at the moment.. so whens my sexual peak????
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
Post Reply