I am using something like that now that handles the highlighting and such. My challenge is when there is more than one block of code or text in the string that needs to be run through.
I was thinking of actually using substitution to remove the code blocks, then HTML-ize the remaining text, then substitute back in the CODE that was removed. But that seems unnecessary if there was a regex that could handle the text that is not wrapped in code tags.
Thanks for the input through. It is much appreciated.
PS There is a nifty highlighter I am using that is really pretty cool. It is lightweight, one class and has a built functionality for parsing PHP functions into links. If anyone is interested I snagged it from
http://web.archive.org/web/200605021523 ... hlight.php.
Also, a la feyd's example, here are a couple of bbCode type parser functions, in case you want one...
This one came from the PHP Manual
Code: Select all
<?php
function bb_php($str){
$str = str_replace("]\n", "]", $str);
$match = array('#\[php\](.*?)\[\/php\]#se');
$replace = array("'<div>'.highlight_string(stripslashes('$1'), true).'</div>'");
return preg_replace($match, $replace, $str);
}
echo bb_php($string);
?>
Using the highlighter code I posted the link to above...
Code: Select all
<?php
function parse_callback($array)
{
require_once 'PHP_Highlight.php';
$h = new PHP_Highlight;
$h->loadString($array[1]);
return $h->toHtmlBlocks(true);
}
echo preg_replace_callback($match, 'parse_callback', $string);
?>
In both cases, $string is the string that contains the text/PHP mash that you want to bbCode parse.