|
 |
|
|
|
|
|
[WIP][PHP] BBcode HTML convertor
 |
|
 |
| |
Svip  |
Posted: Thursday, May 5 2005, 18:29
|
I eat babies

Group: Retired Staff
Joined: Nov 12, 2001


|
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
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
Johnno  |
Posted: Thursday, May 5 2005, 23:39
|
WD&P Ogre

Group: Members
Joined: Sep 15, 2002



|
Reminds me of one I started writing a while ago. Only mine converted between both
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
| |
 |
|
 |
|
|
|
|