", $output);
$output = $smile;
}
// Find a unique symbols for image start and end markers
$imgstartsymbol = "A";
$imgstartmarker = $imgstartsymbol;
while(strpos($output, $imgstartmarker)) $imgstartmarker .= $imgstartsymbol;
$imgendsymbol = "B";
$imgendmarker = $imgendsymbol;
while(strpos($output, $imgendmarker)) $imgendmarker .= $imgendsymbol;
// Find and mark image URLs (so that they don't get converted into normal links)
$output = preg_replace("/http:\/\/(.*\.jpg|\.gif|\.png|\.jpeg)/", $imgstartmarker."$1".$imgendmarker, $output);
// Replace URLs with tags
$output = preg_replace("/http:\/\/(.*?)([\n ])/s", "$1$2", $output);
// Convert marked images to img tags and links
$output = preg_replace("/".$imgstartmarker."(.*?)".$imgendmarker."/s", "", $output);
// Replace [quote title=...]...[/quote]
$urls = "";
while(($start = strpos($output, "[quote"))) {
$pre = substr($output, 0, $start);
$url = substr($output, $start);
$end = strpos($url, "[/quote]") + strlen("[/quote]");
$url = substr($url, 0, $end - strlen("[/quote]"));
$post = substr($output, $start + $end + strlen("[/quote]") );
$header = substr($url, 0, strpos($url, "]") + 1);
$body = substr($url, strpos($url, "]") + 1);
$header = str_replace(array("title"), "", $header);
$header = str_replace(array("="), "
", $header);
$header = str_replace(array("[quote"), "
", $header);
$header = str_replace(array("]"), "
", $header);
$urls .= $pre . $header . $body . "
";
$output = $post;
}
$urls .= $output;
$output = $urls;
//
// Hack to make quotes two levels deep.
//
// Replace [quote title=...]...[/quote]
$urls = "";
while(($start = strpos($output, "[quote"))) {
$pre = substr($output, 0, $start);
$url = substr($output, $start);
$end = strpos($url, "[/quote]") + strlen("[/quote]");
$url = substr($url, 0, $end - strlen("[/quote]"));
$post = substr($output, $start + $end + strlen("[/quote]") );
$header = substr($url, 0, strpos($url, "]") + 1);
$body = substr($url, strpos($url, "]") + 1);
$header = str_replace(array("title"), "", $header);
$header = str_replace(array("="), "", $header);
$header = str_replace(array("[quote"), "
", $header);
$header = str_replace(array("]"), "
", $header);
$urls .= $pre . $header . $body . "
";
$output = $post;
}
$urls .= $output;
$output = $urls;
$search = array('/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is');
$replace = array('$1',
'$1',
'$1');
$output = preg_replace ($search, $replace, $output);
// Replace newlines with
tags
$nls = array("\n");
$nls = str_replace($nls, "
\n", $output);
$output = $nls;
return $output;
}
?>