11header(
'Content-Type: text/html; charset=utf-8');
13error_reporting(E_ALL);
18if (is_readable(
'../geshi.php')) {
20} elseif (is_readable(
'geshi.php')) {
23 die(
'Could not find geshi.php - make sure it is in your include path!');
25require
$path .
'geshi.php';
28if (isset(
$_POST[
'submit'])) {
29 if (get_magic_quotes_gpc()) {
32 if (!strlen(trim(
$_POST[
'source']))) {
33 $_POST[
'language'] = preg_replace(
'#[^a-zA-Z0-9\-_]#',
'',
$_POST[
'language']);
34 $_POST[
'source'] = implode(
'', @file(
$path .
'geshi/' .
$_POST[
'language'] .
'.php'));
35 $_POST[
'language'] =
'php';
66 $geshi->set_overall_style(
'font: normal normal 90% monospace; color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;',
false);
77 $geshi->set_line_style(
'color: #003030;',
'font-weight: bold; color: #006060;',
true);
78 $geshi->set_code_style(
'color: #000020;',
true);
88 $geshi->set_header_content(
'<SPEED> <TIME> GeSHi © 2004-2007, Nigel McNie, 2007-2008 Benny Baumann. View source of example.php for example of using GeSHi');
89 $geshi->set_header_content_style(
'font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
92 $geshi->set_footer_content(
'Parsed in <TIME> seconds at <SPEED>, using GeSHi <VERSION>');
93 $geshi->set_footer_content_style(
'font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
99<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
100 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
101<html xmlns=
"http://www.w3.org/1999/xhtml" xml:lang=
"en" lang=
"en">
103 <title>
GeSHi examples</title>
104 <style type=
"text/css">
107 if (isset(
$_POST[
'submit'])) {
109 echo
$geshi->get_stylesheet(
true);
113 background-
color: #f0f0f0;
116 font-family: Verdana, Arial, sans-serif;
118 border: 2px solid #e0e0e0;
119 background-
color: #fcfcfc;
123 margin: .1em 0 .2em .5em;
124 border-bottom: 1px solid #b0b0b0;
130 margin: .1em 0 .2em .5em;
144 border: 1px solid #b0b0b0;
160<h2>
GeSHi Example Script</h2>
161<
p>To use
this script, make sure that <strong>
geshi.php</strong> is in the parent directory or in your
162include_path, and that the language files are in a subdirectory of
GeSHi's directory called <strong>geshi/</strong>.</p>
163<p>Enter your source and a language to highlight the source in and submit, or just choose a language to
164have that language file highlighted in PHP.</p>
166if (isset($_POST['submit
'])) {
168 echo $geshi->parse_code();
172<form action="?" method="post">
173<h3>Source to highlight</h3>
175<textarea rows="10" cols="60" name="source" id="source"><?php echo $fill_source ? htmlspecialchars($_POST['source
']) : '' ?></textarea>
177<h3>Choose a language</h3>
179<select name="language" id="language">
181if (!($dir = @opendir(dirname(__FILE__) . '/
geshi'))) {
182 if (!($dir = @opendir(dirname(__FILE__) . '/../
geshi'))) {
183 echo '<option>No languages available!</option>
';
187while ($file = readdir($dir)) {
188 if ( $file[0] == '.
' || strpos($file, '.
', 1) === false) {
191 $lang = substr($file, 0, strpos($file, '.
'));
192 $languages[] = $lang;
196foreach ($languages as $lang) {
197 if (isset($_POST['language
']) && $_POST['language
'] == $lang) {
198 $selected = 'selected=
"selected"';
202 echo '<option value=
"' . $lang . '" '. $selected .'>
' . $lang . "</option>\n";
209<input type="submit" name="submit" value="Highlight Source" />
210<input type="submit" name="clear" onclick="document.getElementById('source
').value='';document.getElementById('language
').value='';return false" value="clear" />
213<div id="footer">GeSHi © Nigel McNie, 2004, released under the GNU GPL<br />
214For a better demonstration, check out the <a href="http://qbnz.com/highlighter/demo.php">online demo</a>
if(strncmp( $real_path, SOURCE_ROOT, $base_path_len)) if(!file_exists($path)) $geshi
An exception for terminatinating execution or to throw for unit testing.
const GESHI_HOVER
Links in the source in the :hover state.
const GESHI_LINK
Links in the source in the :link state.
const GESHI_HEADER_PRE_VALID
Use a pre to wrap lines when line numbers are enabled or to wrap the whole code.
const GESHI_FANCY_LINE_NUMBERS
Use fancy line numbers when building the result.
if(PHP_SAPI !='cli') color
A simple script which outputs the CSS classes for all languages supported by GeSHi.