Jump to content

» «

[WIP][PHP] BBcode HTML convertor

1 reply to this topic
  • Svip

    I eat babies

  • The Connection
  • Joined: 12 Nov 2001
  • None
  • Best Returning Member 2014
    Lifetime Achievement Award


Posted 05 May 2005 - 06:29 PM


Okay. This convertor converts HTML to BBcode, so if you have copied a page and want to make it able for people to view on here, but you know that these forums doesn't support HTML, you would like it converted to BBcode.

This page is your change.

It should also be possible to go the other way around, but not yet though.

However, here is the code:
function fix_tablecode($text) {
return '[table]'.preg_replace('#\<tr(.+?)(.+?)\</tr\>#ies', "fix_trcode('\\2')", $text).'[/table]';
function fix_trcode($text) {
$find = array(
$replace = array(
return '[tr]'.preg_replace($find, $replace, $text).'[/tr]';
if ($_POST['bthsubmit']) {
$text = str_replace('\\', '', $_POST['htmlcode']);
$find = array(
 '@\<a href\=\"(.*?)\"(.*?)\>(.*?)\</a\>@is',
$replace = array(
$bbcode = preg_replace($find, $replace, $text);
elseif ($_POST['htbsubmit']) {

$form = '<form action="bbcoder.php" method="post"><div><label for="htmlcode">HTML input/output:</label><br /><textarea name="htmlcode" id="htmlcode" cols="97%" rows="15">'.$htmlcode.'</textarea><br /><br /><span><input type="submit" value="HTML 2 BBcode" name="bthsubmit"><input type="submit" value="BBcode 2 HTML" name="htbsubmit"></span><br /><label for="bbcode">BBCode input/output:</label><br /><textarea name="bbcode" id="bbcode" cols="97%" rows="15">'.$bbcode.'</textarea>';
$html = $form;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/ xhtml1/DTD/xhtml1-strict.dtd">
<title>HTML BBCode convertor</title>
<body align="center">
<?= $html ?>

Remember; it's still WIP

  • Johnno

    WD&P Ogre

  • Members
  • Joined: 15 Sep 2002


Posted 05 May 2005 - 11:39 PM

Reminds me of one I started writing a while ago. Only mine converted between both tounge.gif

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users