Here is two main functions. First function will call second function and second function will highlight the code and return the result to first function.
<?php
// function to call
function highlight_code($txt){
$hasil = preg_replace_callback('{\[code\]((.|\n)+?)\[/code\]}i',"replace_code", $txt);
return $hasil;
}
// main function
function replace_code($ketemu){
$hasil = trim($ketemu[1], "\n ");
return highlight_string($hasil, true);
}
?>
Here is a sample of usage:
<?php
// sample of usage:
$string = "It's how to call PHP info: [code]<?php phpinfo(); ?>[ /code]";
echo highlight_code($string);
?>
Jason Hopkins wrote :1821
What exactly is the point in this? It would be faster and
simpler to strip the tags, highlight the code, and then
replace the tags. 'preg_replace_callback' makes this
script a little to slow to be useful. (On a side
note...I've learned that it's a little easier/faster to
scan through each letter looking for the tags and then
doing what needs to be done withing the tags.