Byron Posted September 20, 2011 Posted September 20, 2011 If your lke me, sometimes you need to show the source of your php script. You can highlight (color code) your php code with the highlight_file() function. By using the .phps extension you can just make a copy of the php file and then rename it with the phps extension like below: Working file: http://helio.byrondallas.heliohost.org/server_load_s.gif Highlighted file: http://helio.byrondallas.heliohost.org/server_load_s.phps First create a file named phpsource.php in your root directory and add the code below: <?php if (substr($_GET['file'],strpos($_GET['file'],'.')) == '.phps') { highlight_file($_GET['file']); } ?> Then add these two lines to your root .htaccess file: RewriteEngine On RewriteRule ^(.+.phps)$ phpsource.php?file=$1 [L] Now you can show the source of any php file by adding the .phps extension. There's also another way which I use more often and that's using the highlight_string() function. <?php highlight_string('YOUR PHP CODE HERE'); ?> I normally just add that to the bottom of an example page, like the example below: http://helio.byrondallas.heliohost.org/email_form.php Just remember if you use single quotes to wrap your code in, you'll need backslash ALL single quotes inside your code \'. Same way if you use double quotes to wrap your code in, then you'll need to backslash ALL of the double quotes in your code \".
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now