IMG

 
IMG
IMG   IMG
  Welcome to GTAForums! Be sure to check out the Grand Theft Auto V Forum.

You are not registered! (If you are, click here to login) Registering is fast, free and easy and allows you to instantly reply to any topic on GTAForums.
Why wait? Click here to register your own unique username and become part of the ever-growing community!


( Log In | Register | Revalidate Validation E-mail )
Quick Log-In:
  IMG
       
>
  Reply to this topicStart new topicStart Poll

 [WIP][PHP] BBcode HTML convertor

 
Svip  
Posted: Thursday, May 5 2005, 18:29
Quote Post


I eat babies
Group Icon
Group: Retired Staff
Joined: Nov 12, 2001

dk.gif

XXXXX



sviip.dk/stuff/bbcoder.php

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:
CODE
<?php
function fix_tablecode($text) {
return '[table]'.preg_replace('#\<tr(.+?)(.+?)\</tr\>#ies', "fix_trcode('\\2')", $text).'[/table]';
}
function fix_trcode($text) {
$find = array(
 '@\<td(.*?)\>(.*?)\</td\>@is',
 '@\<th(.*?)\>(.*?)\</th\>@is',
);
$replace = array(
 '[td]$2[/td]',
 '[th]$2[/th]',
);
return '[tr]'.preg_replace($find, $replace, $text).'[/tr]';
}
if ($_POST['bthsubmit']) {
$text = str_replace('\\', '', $_POST['htmlcode']);
$find = array(
 '@\<b\>(.*?)\</b\>@is',
 '@\<i\>(.*?)\</i\>@is',
 '@\<a href\=\"(.*?)\"(.*?)\>(.*?)\</a\>@is',
 '#\<table(.+?)(.+?)\</table\>#ies',
 '@\<font(.*?)color\=\"(.*?)\"(.*?)\>(.*?)\</font\>@is',
 '@\<span(.*?)style\=\"(.*?)color:(.*?)(.*?)\"(.*?)\>(.*?)\</span\>@is',
);
$replace = array(
 '[b]$1[/b]',
 '[i]$1[/i]',
 '[url=$1]$3[/url]',
 "fix_tablecode('\\2')",
 '[color=$2]$4[/color]',
 '[color=$3]$6[/color]',
);
$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">
<html>
<head>
<title>HTML BBCode convertor</title>
</head>
<body align="center">
<?= $html ?>
</body>
</html>


Remember; it's still WIP
Users WebsitePMAOLYahooICQPlayStation Network
  Top
 

 
Johnno  
Posted: Thursday, May 5 2005, 23:39
Quote Post


WD&P Ogre
Group Icon
Group: Members
Joined: Sep 15, 2002

au.gif

Member Award




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

 

0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)

0 Members:

Topic Options Reply to this topicStart new topicStart Poll
Search topic for posted by (exact match)



 
IMG IMG