<HTML ><HEAD ><TITLE >highlight_file</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Miscellaneous functions" HREF="ref.misc.html"><LINK REL="PREVIOUS" TITLE="get_browser" HREF="function.get-browser.html"><LINK REL="NEXT" TITLE="highlight_string" HREF="function.highlight-string.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.get-browser.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.highlight-string.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.highlight-file" ></A >highlight_file</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN55579" ></A ><P > (PHP 4 )</P >highlight_file -- Syntax highlighting of a file</DIV ><DIV CLASS="refsect1" ><A NAME="AEN55582" ></A ><H2 >Description</H2 >mixed <B CLASS="methodname" >highlight_file</B > ( string filename [, bool return])<BR ></BR ><P > The <B CLASS="function" >highlight_file()</B > function prints out a syntax higlighted version of the code contained in <TT CLASS="parameter" ><I >filename</I ></TT > using the colors defined in the built-in syntax highlighter for PHP. </P ><P > If the second parameter <TT CLASS="parameter" ><I >return</I ></TT > is set to <TT CLASS="constant" ><B >TRUE</B ></TT > then <B CLASS="function" >highlight_file()</B > will return the highlighted code as a string instead of printing it out. If the second parameter is not set to <TT CLASS="constant" ><B >TRUE</B ></TT > then <B CLASS="function" >highlight_file()</B > will return <TT CLASS="constant" ><B >TRUE</B ></TT > on success, <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > The <TT CLASS="parameter" ><I >return</I ></TT > parameter became available in PHP 4.2.0. Before this time it behaved like the default, which is <TT CLASS="constant" ><B >FALSE</B ></TT > </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Care should be taken when using the <A HREF="function.show-source.html" ><B CLASS="function" >show_source()</B ></A > and <B CLASS="function" >highlight_file()</B > functions to make sure that you do not inadvertently reveal sensitive information such as passwords or any other type of information that might create a potential security risk. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Since PHP 4.2.1 this function is also affected by <A HREF="features.safe-mode.html#ini.safe-mode" >safe_mode</A > and <A HREF="features.safe-mode.html#ini.open-basedir" >open_basedir</A >. </P ></BLOCKQUOTE ></DIV ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN55617" ></A ><P ><B >Example 1. Creating a source highlighting URL</B ></P ><P > To setup a URL that can code hightlight any script that you pass to it, we will make use of the "ForceType" directive in Apache to generate a nice URL pattern, and use the function <B CLASS="function" >highlight_file()</B > to show a nice looking code list. </P ><P > In your httpd.conf you can add the following: </P ><P > <DIV CLASS="informalexample" ><A NAME="AEN55623" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><Location /source> ForceType application/x-httpd-php </Location></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > And then make a file named "source" and put it in your web root directory. </P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><HTML> <HEAD> <TITLE>Source Display</TITLE> </HEAD> <BODY BGCOLOR="white"> <?php $script = getenv ("PATH_TRANSLATED"); if(!$script) { echo "<BR><B>ERROR: Script Name needed</B><BR>"; } else { if (ereg("(\.php|\.inc)$",$script)) { echo "<H1>Source of: $PATH_INFO</H1>\n<HR>\n"; highlight_file($script); } else { echo "<H1>ERROR: Only PHP or include script names are allowed</H1>"; } } echo "<HR>Processed: ".date("Y/M/d H:i:s",time()); ?> </BODY> </HTML></PRE ></TD ></TR ></TABLE > </P ><P > Then you can use an URL like the one below to display a colorized version of a script located in "/path/to/script.php" in your web site. </P ><P > <DIV CLASS="informalexample" ><A NAME="AEN55630" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >http://your.server.com/source/path/to/script.php</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ></TD ></TR ></TABLE > </P ><P > See also <A HREF="function.highlight-string.html" ><B CLASS="function" >highlight_string()</B ></A >, <A HREF="function.show-source.html" ><B CLASS="function" >show_source()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.get-browser.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.highlight-string.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >get_browser</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.misc.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >highlight_string</TD ></TR ></TABLE ></DIV ></BODY ></HTML >