Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 839

php-manual-en-4.3.0-2mdk.noarch.rpm

<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&nbsp;--&nbsp;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
>&#13;     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
>&#13;     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
>&#13;     <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
>&#13;       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
>&#13;       In your httpd.conf you can add the following:
      </P
><P
>&#13;       <DIV
CLASS="informalexample"
><A
NAME="AEN55623"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>&#60;Location /source&#62;
    ForceType application/x-httpd-php
&#60;/Location&#62;</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
      </P
><P
>&#13;       And then make a file named "source" and put it in your
       web root directory.
      </P
><P
>&#13;       <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;HTML&#62;
&#60;HEAD&#62;
&#60;TITLE&#62;Source Display&#60;/TITLE&#62;
&#60;/HEAD&#62;
&#60;BODY BGCOLOR="white"&#62;
&#60;?php
    $script = getenv ("PATH_TRANSLATED");
    if(!$script) {
    echo "&#60;BR&#62;&#60;B&#62;ERROR: Script Name needed&#60;/B&#62;&#60;BR&#62;";
    } else {
    if (ereg("(\.php|\.inc)$",$script)) {
    echo "&#60;H1&#62;Source of: $PATH_INFO&#60;/H1&#62;\n&#60;HR&#62;\n";
    highlight_file($script);
    } else {
    echo "&#60;H1&#62;ERROR: Only PHP or include script names are allowed&#60;/H1&#62;"; 
    }
    }
    echo "&#60;HR&#62;Processed: ".date("Y/M/d H:i:s",time());
?&#62;
&#60;/BODY&#62;
&#60;/HTML&#62;</PRE
></TD
></TR
></TABLE
>
      </P
><P
>&#13;       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
>&#13;       <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
>&#13;     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
>