SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP color coding

    Hey, when I use the tags [ php ] [ /php ], your script is coded in nice colors, what's the trick to do this??

  2. #2
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My code always comes out in colour when I put them between php tags.

    PHP Code:
    <?php

    echo "Hello";

    ?>
    PHP Code:
    echo "Hello"

  3. #3
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that's not my question, I mean when I want to display code on my site, and I want It coded in colors, how do I do that?

  4. #4
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    A syntax highlighting system is complex. It parses the language looking for syntax conventions, and placing tags around them to enable them to show up in a certain colour.

    You may find pre-written code to do this for PHP, or you may need to do it yourself.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  5. #5
    ********* Addict
    Join Date
    Apr 2000
    Location
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might be able to find the answer by looking at the source.php file at php.net: [http://php.net/source.php?url=/source.php].

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you are after is the highlight_string() function. It will color code a string based on the colors set for source code coloring in the php.ini file. For instance let's say we pulled a bit of code from a database and stored it in a variable named $data

    If we did

    PHP Code:
    //Produces color-highlighted version of $data
    print highlight_string($data); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Zealot oodie's Avatar
    Join Date
    Jul 2000
    Location
    Misty Mountain
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or if you want to highlight the content of a file, you can use
    PHP Code:
    show_source("filename.php"); 


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
  •