BB Code.. Next
Moderator: General Moderators
BB Code.. Next
I have a file (inc/bbcode.php) now how do i allow it to happen, the bb code replace to the result?
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()?
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
or <span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>..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).
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...
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.
Hope that makes sense
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;
}
?>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