-
Thanks.
Apparently the TRUE return value (second parameter) just enables a built in output buffer.
I added my own (and took off the return value), and I got an identical error message about memory allocation.
I'm just testing a single line of code with it.
I'm confused.
-
does it work without the highlight i couldn't get it workin to, If it works without the highlight then that would be awesome, I dont care about the highlighting...
Thankyou for helping me out!
-
What would be the point of not highlighting it?
My code works fine. It simply doesn't apply the highlight_string function properly.
If you want to rewrite another function, go ahead and replace highlight_string() with it.
-
lol, I am giving up on this bbcode translation, I am going to wait until I know alot more about php, becuase this just confuses the heck out of me
-
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)
-
ty for this, i am gonna try it in a little bit...