Development Wiki

User:Pyramide/PHP Syntaxhighlighter for MediaWiki

From phpBB Development Wiki

< User:Pyramide
Revision as of 09:12, 26 December 2007 by ElorcAdelm (Talk | contribs)

letodronra This is a simple PHP syntaxhighlighter for MediaWiki (inspired by the Syntax Highlighting Extension). It only supports PHP but doesn't require any external tools. The formatting will look exactly like the code you see on this page.

To install, just copy&paste the following code and save it as extensions/phpExtension.php:

[] = "phpExtension";


phpSyntaxHighlight($input$argv) {
//prepare input
$input trim($input);

//if we dont have php tags, add them
$strip_php false;
stristr($input'<'.'?php') === false) {
$input "<"."?php\n$input\n?".">";
$strip_php true;

$output highlight_string($inputtrue);
$strip_php) {
$output str_replace(array('&lt;?php<br />''?&gt;'), ''$output);

//filter out unnescessary stuff
$output str_replace(array('<code>''</code>'"\r""\n"), ''$output);
$output "<pre>$output</pre>";

Then open LocalSettings.php and add this line:


The extension should be ready to use now. Just wrap your PHP code inside <php>...</php> (you dont even need the leading space like for normale code sections).