]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - pgsrc/Help%2FPhpHighlightPlugin
Update PHP Doc
[SourceForge/phpwiki.git] / pgsrc / Help%2FPhpHighlightPlugin
1 Date: Tue,  5 Feb 2013 15:49:31 +0000
2 Mime-Version: 1.0 (Produced by PhpWiki 1.4.0)
3 Content-Type: application/x-phpwiki;
4   pagename=Help%2FPhpHighlightPlugin;
5   flags=PAGE_LOCKED%2CEXTERNAL_PAGE;
6   charset=UTF-8
7 Content-Transfer-Encoding: binary
8
9 The **~PhpHighlight** [[Help:WikiPlugin|plugin]] pretty-prints PHP code using the
10 php-function:highlight-string.
11
12 == Usage ==
13
14 You specify options for the plugin on the same line as ##~<~<~PhpHighlight##,
15 and put the code on the following lines, until the final ##~>~>##:
16
17 {{{
18 <<PhpHighlight [wrap?] [color options]
19 code to be highlighted
20 >>
21 }}}
22
23 == Description ==
24
25 Depending on the ##wrap## option, then the plugin will take care of
26 adding ##<?php## and ##?>## to the code before passing it to
27 php-function:highlight-string. If the PHP delimiters were added, then
28 the plugin removes them again from the highlighted string, before
29 presenting it.
30
31 == Options ==
32
33 === Automatic Wrapping ===
34
35 If you don't want the plugin to automatically wrap the source code
36 in ##<?php## and ##?>##, then set ##wrap## to ##0##. The default value is ##1##
37 which means that the plugin takes care of adding and removing ##<?php## and ##?>## automatically.
38
39 If you set ##wrap## to ##0##, then you'll be able to mix PHP code with
40 HTML. The plugin will then translate '##< ?php##' into '##<?php##' and
41 '##? >##' into '##?>##' to allow you to start and stop PHP mode in your code.
42
43 === Color Options ===
44
45 The plugin accepts optional color arguments which correspond to the
46 highlight settings in **php.ini**. Specified colors must be a valid
47 hexadecimal color or
48 [[http://www.w3.org/TR/REC-html40/types.html#h-6.5|HTML 4 color name]]
49 in lowercase, such as ##'#0f0344'## or ##blue##. You can set the
50 following options: ##string##, ##comment##, ##keyword##, ##bg##, ##default##, and ##html##.
51
52 **Note:** ##bg## no longer exists in PHP 5.4.
53
54 == Examples ==
55
56 === PHP with default colors from ##php.ini##: ===
57
58 <<PhpHighlight
59 function hello() {
60     echo "Hello World<p>";
61 }
62 >>
63
64 === HTML with embedded PHP ===
65
66 Here we have to use ##wrap=0## to prevent automatic wrapping, and escape
67 '##?>##' as '##? >##':
68
69 <<PhpHighlight wrap=0 html='#000000' bg='#dddddd'
70 <html>
71   <head>
72     <title>PHP Test</title>
73   </head>
74   <body>
75     < ?php echo "<p>Hello World</p>\n"; ? >
76   </body>
77 </html>
78 >>
79
80 === C Source ===
81
82 Although ##highlight_string()## was designed with PHP code in mind it is
83 suitable for basic syntax-highlighting of most C code because the two
84 syntax are similar.
85
86 <<PhpHighlight default=black string=blue comment=gray keyword=purple
87 #include <stdio.h>
88 /* Get load */
89 int
90 getload(void)
91 {
92     if ((fp = fopen("/proc/loadavg", "r")) == NULL) {
93         syslog(LOG_ERR, _("%s %s: unable to open %s: %s"), _("FATAL ERROR:"),
94               "getload()", "/proc/loadavg", strerror(errno));
95         exit(EX_OSFILE);
96     }
97     fclose(fp);
98 }
99 >>
100
101 == Known Problems ==
102 {{{
103 <<PhpHighlight
104     testing[somearray];
105     testing~[badworkaround~];
106 >>
107 }}}
108 will swallow "~[somearray~]"
109
110 == Authors ==
111 * [[mailto:gimpster@gimpster.com|Martin Geisler]]
112 * [[mailto:carstenklapp@users.sourceforge.net|Carsten Klapp]] (added ability to override colors defined in ##php.ini##)
113
114 == See Also ==
115 * [[Help:SyntaxHighlighterPlugin|SyntaxHighlighter]] plugin for highlighting other languages.
116
117 <noinclude>
118 ----
119 [[PhpWikiDocumentation]] [[CategoryWikiPlugin]]
120 </noinclude>