PHP Code:
<?php
// Press Start Online SimpleCode translator
// For backwards compatibility, remove trailing slashes from past articles
$original_string = str_replace("/]","]",$original_string);
$original_string = str_replace("’","'",$original_string);
// Search for the following SimpleCodes
$bbcodes = array(
"'\[b\](.*?)\[/b\]'i",
"'\[u\](.*?)\[/u\]'i",
"'\[i\](.*?)\[/i\]'i",
"'\[img\](.*?)\[/img\]'is",
"'\[url\](.*?)\[/url\]'is",
"'\[url=(.*?)\](.*?)\[/url\]'is",
"'\[il=(.*?)\](.*?)\[/il\]'i",
"'(\[1img\](.*?)\[/1img\]'is",
"'\[2img\](.*?)\[/2img\]'is",
"'\[3img\](.*?)\[/3img\]'is",
"'\[1img\](.*?)\[endimg\]'is",
"'\[2img\](.*?)\[endimg\]'is",
"'\[3img\](.*?)\[endimg\]'is",
"'\[quote\](.*?)\[/quote\]'is",
"'\[h2\](.*?)\[/h2\]'i",
"'\[h1\](.*?)\[/h1\]'i",
"'\[fl=(.*?)\](.*?)\[/fl\]'i",
"'\[hr\]'",
"'\[p\]'"
);
// Replace the SimpleCodes with XHTML
$replace = array(
"<strong>\\1</strong>",
"<u>\\1</u>",
"<em>\\1</em>",
"<img src=\"\\1\" alt=\"image\" />",
"<a href=\"\\1\" title=\"\\1\">\\1</a>",
"<a href=\"\\1\" title=\"\\1\">\\2</a>",
"<a href=\"image.php?id=\\1\" title='click for large version'>\\2</a>",
"<div id='oneimage'>\\1</div><div id=\"endfloat\"></div>",
"<div id='twoimages'>\\1</div><div id=\"endfloat\"></div>",
"<div id='threeimages'>\\1</div><div id=\"endfloat\"></div>",
"<div id='oneimage'>\\1</div><div id=\"endfloat\"></div>",
"<div id='twoimages'>\\1</div><div id=\"endfloat\"></div>",
"<div id='threeimages'>\\1</div><div id=\"endfloat\"></div>",
"<div id='quote_box'>\\1</div>",
"<h2>\\1</h2>",
"<h1>\\1</h1>",
"<div id='img_\\1'>\\2</div>",
"<div id=\"hrfix\"><div class=\"sub\"> </div><hr size=\"1\" height=\"1\" width=\"100%\"><div class=\"sub\"> </div></div>",
"<br /><br />"
);
$new_string = preg_replace($bbcodes,$replace,$original_string);
?>
The way this works is that I include it into another file, after the variable $original_string has been declared, and before I echo $new_string. Just so I don't have to edit any other files with it all in. Repeated bits in the array are for backwards compatibility with the existing database entries, which were worked around errors in the previous bbcode script.