mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-20 19:08:54 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@132730 c90b9560-bf6c-de11-be94-00142212c4b1
138 lines
4.2 KiB
XML
138 lines
4.2 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.7 $ -->
|
|
<!-- splitted from ./en/functions/misc.xml, last change in rev 1.22 -->
|
|
<refentry id="function.highlight-file">
|
|
<refnamediv>
|
|
<refname>highlight_file</refname>
|
|
<refpurpose>Syntax highlighting of a file</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>highlight_file</methodname>
|
|
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
|
|
<methodparam
|
|
choice="opt"><type>bool</type><parameter>return</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
The <function>highlight_file</function> function prints out a syntax
|
|
higlighted version of the code contained in <parameter>filename</parameter>
|
|
using the colors defined in the built-in syntax highlighter for PHP.
|
|
</simpara>
|
|
<simpara>
|
|
If the second parameter <parameter>return</parameter> is set to &true;
|
|
then <function>highlight_file</function> will return the highlighted
|
|
code as a string instead of printing it out. If the second parameter is
|
|
not set to &true; then <function>highlight_file</function> will
|
|
return &true; on success, &false; on failure.
|
|
</simpara>
|
|
<note>
|
|
<simpara>
|
|
The <parameter>return</parameter> parameter became available in PHP
|
|
4.2.0. Before this time it behaved like the default, which is &false;
|
|
</simpara>
|
|
</note>
|
|
<caution>
|
|
<simpara>
|
|
Care should be taken when using the
|
|
<function>show_source</function> and
|
|
<function>highlight_file</function> 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.
|
|
</simpara>
|
|
</caution>
|
|
<note>
|
|
<simpara>
|
|
Since PHP 4.2.1 this function is also affected by <link
|
|
linkend="ini.safe-mode">safe_mode</link> and <link
|
|
linkend="ini.open-basedir">open_basedir</link>.
|
|
</simpara>
|
|
</note>
|
|
<simpara>
|
|
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 <function>highlight_file</function> to show a nice looking
|
|
code list.
|
|
</simpara>
|
|
<simpara>
|
|
In your &httpd.conf; you can add the following:
|
|
</simpara>
|
|
<para>
|
|
<example>
|
|
<title>Creating a source highlighting URL</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
<Location /source>
|
|
ForceType application/x-httpd-php
|
|
</Location>
|
|
]]>
|
|
</programlisting>
|
|
<simpara>
|
|
And then make a file named "source" and put it in your
|
|
web root directory.
|
|
</simpara>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<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>
|
|
]]>
|
|
</programlisting>
|
|
<simpara>
|
|
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.
|
|
</simpara>
|
|
<screen>
|
|
<![CDATA[
|
|
http://your.server.com/source/path/to/script.php
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<simpara>
|
|
See also <function>highlight_string</function>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|