SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: PHP color coding
-
May 26, 2001, 14:22 #1
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??
-
May 26, 2001, 15:25 #2
- 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";
-
May 27, 2001, 05:09 #3
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?
-
May 27, 2001, 05:23 #4
- 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
-
May 27, 2001, 05:28 #5
- 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].
-
May 27, 2001, 09:50 #6
- 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.
-
May 27, 2001, 11:16 #7
- 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