PHPExecute

Summary: Lets you execute PHP-Code in any page.
Version: 0.9 2008-12-07
Prerequisites:
Status: BETA
Maintainer: Michael Selbmann

Questions answered by this recipe

How can I execute PHP-Code in a page?

Description

Lets you execute PHP-Code in any page.

Notes

It was only tested with simple code snippets.
Security Warning:
Never install this recipe on a wiki which allows public editing of its pages, only install it on a wiki if you can trust all your editors! This recipe enables the insertion of dangerous code. Use at your own risk and weigh up this risk very carefully!

Release Notes

It is even not a beta, it is still a gamma-Version. Use at your own risk :-)

Installation

Put this in yout local/config.php

Markup('php','<include','/\(\:php\:\)(.*?)\(\:phpend\:\)/sie', "php('$1')");
function php($cmd)
	{
	$cmd = str_replace('\\"', '"', $cmd);
	$out = "";
	eval($cmd);
	return $out;
	}

Now you can execute simple PHP-Code in any pages.

Like:
(:php:)
$out = {$FullName} . "\n";
$arr = Array("a", "b", "c");
$cnt = 0;
foreach($arr as $line)
  {
  $cnt++;
  $out .= "||$line||$cnt\n";
  }
$out .= "FOO\\\\\n" . "BAR:" . (3*4);
(:phpend:)

Contributor

Michael Selbmann

Comments

Patricia - France (bad english)

That don't work with :

(:php:)
include("column_left.php");
(:phpend:)

and a message error appears on the top :
Parse error: syntax error, unexpected '<' in /var/www/vhosts/domain/httpdocs/local/markup.php(6) : eval()'d code on line 2
markup.php is include in config.php (whenever directly in config.php : the same error)

Nota 1 : column-left.php contains a simple table.

Nota 2 : the code dont appears in the source code

Nota 3 : Your example on the top is correctly work on the same pmwiki page

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.