SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    displaying code segments in diff. colors

    hey guys!

    how do i display the code segments like some posts.. where some code fragments come up in orange, green and blue. Would make my code postings easier!

  2. #2
    SitePoint Enthusiast Ckeren's Avatar
    Join Date
    Jun 2001
    Location
    AU
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you sould have some sort of word filtering between [phpee] [/phpee] and make sure the code not inside the php tag <??>

  3. #3
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you mean i start off the code with a [phpee] tag, enter the code and close with a [/phpee] tag?

    and i leave the <? and ?> out of the code?

  4. #4
    SitePoint Enthusiast Ckeren's Avatar
    Join Date
    Jun 2001
    Location
    AU
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    emmmmm pardon me, I don't really get it .

    Well this is my algorithm that may be might help you.

    first scan thru if there is anything in the text which is starting with [phpee] and end with [/phpee] if there is any code within that tag, then it should go to php filter(well of course inside this filter function should do the trick) Your filter function should print the whole code that's been modified and print it as plain text.

    for example <?php ?> may be should do like this: print "\<\?php \?\>";

    You've got to deal with regular expression and string manipulation.

  5. #5
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you trying to make the PHP code that you print to the page (after altering so it doesn't muck up your page, ie running htmlspecialchar()) go to different colours?

    highlight_string("&lt;?$string?>");

    http://www.php.net/manual/en/functio...ght-string.php

  6. #6
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no no... noooooo...

    looks like I confused everyone here.

    What I'm talking about is the code that I put HERE, in this forum. I note that certain code segments, come up in different colors for easy identification.. there's red, yellow, orange and blue. Plus the font is smaller too, and makes it easier to read by everyone.

    Eg: I post a question. You post the answer in the form of a code fragment. Most of the time it's nicely color-coded and in a diff. font....

    Is it any clearer now?

    I want to know how to do that. Putting the code in diff. colors and such.

  7. #7
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well what you are doing is going through your user input, when you hit a [ php] in this forum, it goes and fetches the stuff inside that until the [\ php] and then you can either use the pre-built php function from above, which I mentioned, or you can make your own one, which would be create a complex task to colourise the code.

  8. #8
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by timnz
    Well what you are doing is going through your user input, when you hit a [ php] in this forum, it goes and fetches the stuff inside that until the [\ php] and then you can either use the pre-built php function from above, which I mentioned, or you can make your own one, which would be create a complex task to colourise the code.
    yikes that difficult huh? man.. i just thought there was some sort of easy stuff to call... guess not. It would make it easier for me when I post my code.. so ppl could see it easier...

  9. #9
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something like this should work fine i think.

    PHP Code:
    $text preg_replace('#\\[ php](.+?)\\[/ php]#eis''highlight_string("$1")'$text); 
    try that. (take out the spaces before "php" in the reg exp.)
    Last edited by DR_LaRRY_PEpPeR; Jul 12, 2001 at 20:32.

  10. #10
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DR_LaRRY_PEpPeR
    something like this should work fine i think.

    PHP Code:
    $text preg_replace('#\[ php](.+?)\[/ php]#eis''highlight_string("$1")'$text); 
    try that. (take out the spaces before "php" in the reg exp.)
    hey hold on a sec.. what did you do to get the:

    PHP
    --------------------------------------

    --------------------------------------

    box? I think that's what I want. All my PHP code should then be colored correctly when inside that box right?

  11. #11
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wait.. let me try something...

    PHP Code:

    echo ("bla");
    echo (
    "bla bla");
    echo (
    "bla bla bla"); 
    the above should come up colorized properly.........

    PERFECT!! THAT is what I want.......

  12. #12
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
      echo "oops"
    Last edited by MattR; Jul 12, 2001 at 06:15.

  13. #13
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think everyone has misunderstood the rather simple question infinitium has asked.

    To post your code HERE in this forum and have it all pretty and colour coded you need to place the code within [p h p] and [/ p h p] tags (Remove the whitespace I put into those tags, that was to stop vBulletin from parsing the tags).

    So if you type (without the whitespace in the tags)

    [p h p]
    <?php
    $foo = 'bar';
    echo $foo;
    ?>
    [/p h p]

    This is how the code will appear in the forum:
    PHP Code:
    <?php
    $foo 
    'bar';
    echo 
    $foo;
    ?>
    Read this page for more info:
    http://sitepointforums.com/misc.php?s=&action=bbcode

    - I just re-read your last post infinitium, obviously you have worked it out
    Last edited by freakysid; Jul 12, 2001 at 06:03.

  14. #14
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe.. yeah FreakySid.. everyone did!

    Wow.. amazing code you guys can come up with... tsk tsk...

    Anyway, I've solved it. Simply matter of opening and closing PHP tags. This will def. make my code more legible in future postings.

    Thanks anyway guys!

  15. #15
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, if I had read your first post in full I would have understood, subsequently I didn't, and had thought you wanted to know how to "do" it, rather than how to "do" it.

  16. #16
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe.. yeah! My favourite was Dr_Larry_Pepper's

    PHP Code:
    $text preg_replace('#[ php](.+?)[/ php]#eis''highlight_string("$1")'$text); 
    WOW! Not that i understand any of it until now....

    And no thanks, please don't explain it to me....

  17. #17
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    crap! sorry infinitium i posted that late and didn't review it. there's a little mistake cuz of stupid VB. there needs to be a "\" before the 2 "[" or it will be interpreted as a character class. the backslash in front will let you match a literal "[", which is what you want.

    again, sorry.

  18. #18
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DR_LaRRY_PEpPeR
    crap! sorry infinitium i posted that late and didn't review it. there's a little mistake cuz of stupid VB. there needs to be a "\" before the 2 "[" or it will be interpreted as a character class. the backslash in front will let you match a literal "[", which is what you want.

    again, sorry.
    uhh.. actually.. it's NOT what i want... hehe.... just scroll up a lil' and you'll know what I mean... but thank YOU anyway!

  19. #19
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops! i didn't even get it that you mean on HERE! ok ok, i got it now. sorry.

  20. #20
    SitePoint Enthusiast nguip's Avatar
    Join Date
    Apr 2001
    Location
    Malaysia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HAhahahahahahaah Good joke for me in this stressful hour
    Ngu I.P.
    Web Developer

  21. #21
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey nguip.. you're from malaysia? Cool... so am I!

    Whereabouts? KL?

  22. #22
    SitePoint Enthusiast nguip's Avatar
    Join Date
    Apr 2001
    Location
    Malaysia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yoo.......

    Yup.. I'm in PJ how about u ?
    Ngu I.P.
    Web Developer

  23. #23
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    penang guy... been to KL a few times. Parking in PJ is like hell.. cannot find places esp. in USJ....

  24. #24
    SitePoint Enthusiast nguip's Avatar
    Join Date
    Apr 2001
    Location
    Malaysia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow...

    I guess we better PM or email man....

    I don't think we should post these chit chat here
    Ngu I.P.
    Web Developer

  25. #25
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure.. PM me or email....


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
  •