<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="home" title="HomePage" href="HomePage.html" />
<link rel="help" title="HowToUseWiki" href="HowToUseWiki.html" />
<link rel="copyright" title="GNU General Public License" href="http://www.gnu.org/copyleft/gpl.html#SEC1" />
<link rel="author" title="The PhpWiki Programming Team" href="http://phpwiki.org/ThePhpWikiProgrammingTeam" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Language" content="en" />
<meta name="robots" content="noindex,nofollow" />
<meta name="language" content="en" />
<meta name="document-type" content="Public" />
<meta name="document-rating" content="General" />
<meta name="generator" content="PhpWiki" />
<meta name="PHPWIKI_VERSION" content="1.3.14" />

<link rel="stylesheet" type="text/css" charset="iso-8859-1" href="phpwiki-printer.css" />
<title>PhpWiki - Php Highlight Plugin</title>
</head>
<body>

<div id="header">
  
<!-- Page title -->
<h1>Php Highlight Plugin</h1>
</div>
<div id="content">



<div class="wikitext"><p class="tightenable top">The <a href="PhpHighlightPlugin.html" class="wiki">PhpHighlightPlugin</a> pretty-prints PHP code using the
<a href="http://www.php.net/highlight-string" class="interwiki"><span style="white-space: nowrap"><img src="images/interwiki.png" alt="" class="linkicon" border="0" />php-function:</span><span class="wikipage">highlight-string</span></a>.</p>
<h2>Usage</h2>
<p class="tightenable">You specify options for the plugin on the same line as the <tt>&lt;?plugin</tt>,
and put the code on the following lines, until the final <tt>?&gt;</tt>:</p>
<pre class="tightenable">
&lt;?plugin PhpHighlight [wrap?] [color options]
code to be highlighted
?&gt;</pre>
<h2>Description</h2>
<p class="tightenable">Depending on the <tt>wrap</tt> option, then the plugin will take care of
adding <tt>&lt;?php</tt> and <tt>?&gt;</tt> to the code before passing it to
<a href="http://www.php.net/highlight-string" class="interwiki"><span style="white-space: nowrap"><img src="images/interwiki.png" alt="" class="linkicon" border="0" />php-function:</span><span class="wikipage">highlight-string</span></a>. If the PHP delimiters were added, then
the plugin removes them again from the highlighted string, before
presenting it.</p>
<h2>Options</h2>
<dl><dt class="tightenable">Automatic Wrapping</dt>
<dd class="tightenable"><p class="tightenable top">If you don't want the plugin to automatically wrap the source code
in <tt>&lt;?php</tt> and <tt>?&gt;</tt>, then set <tt>wrap</tt> to <tt>0</tt>. The default value is <tt>1</tt>
which means that the plugin takes care of adding and removing
<tt>&lt;?php</tt> and <tt>?&gt;</tt> automatically.</p>
<p class="tightenable bottom">If you set <tt>wrap</tt> to <tt>0</tt>, then you'll be able to mix PHP code with
HTML. The plugin will then translate '<tt>&lt; ?php</tt>' into '<tt>&lt;?php</tt>' and
'<tt>? &gt;</tt>' into '<tt>?&gt;</tt>' to allow you to start and stop PHP mode in your
code.</p>
</dd>
<dt class="tightenable">Color Options</dt>
<dd class="tightenable"><p class="tightenable top">The plugin accepts optional color arguments which correspond to the
highlight settings in <b>php.ini</b>. Specified colors must be a valid
hexadecimal color or
<a href="http://www.w3.org/TR/REC-html40/types.html#h-6.5" target="" class="namedurl"><span style="white-space: nowrap"><img src="images/http.png" alt="" class="linkicon" border="0" />HTML</span> 4 color name</a>
in lowercase, such as <tt>'#0f0344'</tt> or <tt>blue</tt>. You can set the
following options:</p>
<p class="tightenable bottom"><tt>string</tt>, <tt>comment</tt>, <tt>keyword</tt>, <tt>bg</tt>, <tt>default</tt>, and <tt>html</tt></p>
</dd>
</dl>
<h2>Examples</h2>
<h3>PHP with default colors from <tt>php.ini</tt>:</h3>
<div class="plugin tightenable" id="PhpHighlightPlugin5"><code><font color="#000000">
<font color="#007700">function </font><font color="#0000BB">hello</font><font color="#007700">() {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Hello World&lt;p&gt;"</font><font color="#007700">;<br />}<br /></font>
</font>
</code></div>
<h3>HTML with embedded PHP</h3>
<p class="tightenable">Here we have to use <tt>wrap=0</tt> to prevent automatic wrapping, and escape
'<tt>?&gt;</tt>' as '<tt>? &gt;</tt>':</p>
<div class="plugin tightenable" id="PhpHighlightPlugin6"><code><font color="#000000">
&lt;html&gt;<br />&nbsp;&nbsp;&lt;head&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;PHP Test&lt;/title&gt;<br />&nbsp;&nbsp;&lt;/head&gt;<br />&nbsp;&nbsp;&lt;body&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000BB">&lt;?php </font><font color="#007700">echo </font><font color="#DD0000">"&lt;p&gt;Hello World&lt;/p&gt;\n"</font><font color="#007700">; </font><font color="#0000BB">?&gt;<br /></font>&nbsp;&nbsp;&lt;/body&gt;<br />&lt;/html&gt;</font>
</code></div>
<h3>C Source</h3>
<p class="tightenable">Although <tt>highlight_string()</tt> was designed with PHP code in mind it is
suitable for basic syntax-highlighting of most C code because the two
syntax are similar.</p>
<div class="plugin tightenable" id="PhpHighlightPlugin7"><code><font color="#000000">
<font color="gray">#include &lt;stdio.h&gt;<br />/* Get load */<br /></font><font color="black">int<br />getload</font><font color="purple">(</font><font color="black">void</font><font color="purple">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;if ((</font><font color="black">fp </font><font color="purple">= </font><font color="black">fopen</font><font color="purple">(</font><font color="blue">"/proc/loadavg"</font><font color="purple">, </font><font color="blue">"r"</font><font color="purple">)) == </font><font color="black">NULL</font><font color="purple">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="black">syslog</font><font color="purple">(</font><font color="black">LOG_ERR</font><font color="purple">, </font><font color="black">_</font><font color="purple">(</font><font color="blue">"%s %s: unable to open %s: %s"</font><font color="purple">), </font><font color="black">_</font><font color="purple">(</font><font color="blue">"FATAL ERROR:"</font><font color="purple">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="blue">"getload()"</font><font color="purple">, </font><font color="blue">"/proc/loadavg"</font><font color="purple">, </font><font color="black">strerror</font><font color="purple">(</font><font color="black">errno</font><font color="purple">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</font><font color="black">EX_OSFILE</font><font color="purple">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="black">fclose</font><font color="purple">(</font><font color="black">fp</font><font color="purple">);<br />}<br /></font>
</font>
</code></div>
<h2>Authors</h2>
<p class="tightenable bottom">Martin Geisler <a href="mailto:gimpster@gimpster.com" target="" class="namedurl"><span style="white-space: nowrap"><img src="images/mailto.png" alt="" class="linkicon" border="0" />gimpster@gimpster.com</span></a> and Carsten Klapp
<a href="mailto:carstenklapp@users.sourceforge.net" target="" class="namedurl"><span style="white-space: nowrap"><img src="images/mailto.png" alt="" class="linkicon" border="0" />carstenklapp@users.sourceforge.net</span></a>.</p>
</div>

<div id="footer">  <hr class="printer" noshade="noshade" />
<p class="editdate">Owner: &quot;admin&quot;  Last edited on January 9, 2004 10:34 am by &quot;The PhpWiki programming team&quot;</p>
</div>

</div>
<!-- Add your Disclaimer here -->
</body>
</html>
