Page 3 of 3 FirstFirst 123
Results 21 to 26 of 26

Thread: Showing php in bbcode

  1. #21
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #22
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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!
    Hey new design new look, goto xudas for personal webdsign help.. (:

  3. #23
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #24
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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
    Hey new design new look, goto xudas for personal webdsign help.. (:

  5. #25
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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)
    Last edited by djr33; 09-25-2007 at 07:06 AM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #26
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ty for this, i am gonna try it in a little bit...
    Hey new design new look, goto xudas for personal webdsign help.. (:

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •