Here's a more understandable version of the code. If you want to play with it, go ahead. It works. I just don't know how to properly use the highlight function with an output buffer.
Code:
while (strpos($c,'[php]')!==FALSE&&strpos($c,'[/php]',strpos($c,'[php]'))!==FALSE) {
$d = substr($c,0,5+strpos($c,'[php]'));
ob_start();
highlight_string(substr($c,strpos($c,5+strpos($c,'[php]'),6+strpos($c,'[/php]',strpos($c,'[php]')))));
$d .= ob_get_clean();
$d .= substr($c,6+strpos($c,'[/php]',strpos($c,'[php]')));
$c = $d;
}
And here's that again, with detailed comments:
Code:
while (strpos($c,'[php]')!==FALSE&&strpos($c,'[/php]',strpos($c,'[php]'))!==FALSE) {
//while it is true that the PHP start tag exists in the string AND there is a PHP close tag [after that]:
$d = substr($c,0,5+strpos($c,'[php]'));
//set a new variable, $d to the first part of the string-- the part before the PHP open tag
ob_start();
//start the output buffer-- all output is stored into it and not sent to the browser
highlight_string(substr($c,strpos($c,5+strpos($c,'[php]'),6+strpos($c,'[/php]',strpos($c,'[php]')))));
//ok, this is the big confusing line-- i'll break it down a bit below...
//in short, get the part between the php tags and output that into the buffer as highlighted
$d .= ob_get_clean();
//add to the end of $d the contents of the output buffer and end the buffer
$d .= substr($c,6+strpos($c,'[/php]',strpos($c,'[php]')));
//add to the end of $d the last part of the string, starting at the first PHP close tag after the first PHP open tag
$c = $d;
//set $c to the new value, $d, for use in the next cycle of the loop or later
//$d was just temporary to get the parts out one at a time
}
//end loop
Ok, and here's a breakdown of that ugly line:
highlight_string(substr($c,strpos($c,5+strpos($c,'[php]'),6+strpos($c,'[/php]',strpos($c,'[php]')))));
>highlightthis([see below]) ...and output [part of the function automatically]
->get the part of the string $c that meets these conditions:
substr($c,5 after the position of the start tag, 6 after the position of the close tag after the start tag)
remember: substr(string,start at, length)
Bookmarks