How can preg_replace call a function in the same class?
I have tried the following:
<?php
defined('IN_SCRIPT') or exit;
class Templates {
protected $db;
function __construct(&$db) {
$this->db = &$db;
$settings = new Settings($this->db);
$gamebase = new Gamebase($this->db);
$this->theme = $settings->theme_id;
$this->gameid = $gamebase->getId();
}
function get($template) {
$query = $this->db->execute("
SELECT `main_templates`.`content`
FROM `main_templates`
INNER JOIN `main_templates_group`
ON `main_templates_group`.`id` = `main_templates`.`gid`
INNER JOIN `main_themes`
ON `main_themes`.`id` = `main_templates_group`.`tid`
WHERE
`main_themes`.`id` = '".$this->theme."'
&&
`main_templates`.`name` = '".$template."'
");
while ($templates = mysql_fetch_array($query)) {
$content = $templates['content'];
// Outcomment
$pattern[] = "/\/\*(.*?)\*\//is";
$replace[] = "";
// Call a template
$pattern[] = "/\[template\](.*?)\[\/template\]/is";
$replace[] = $this->get('header');
$content = preg_replace($pattern, $replace, $content);
return $content;
}
}
}
But that just comes out with the following error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
As soon as I outcomment this:
// Call a template
$pattern[] = "/\[template\](.*?)\[\/template\]/is";
$replace[] = $this->get('header');
Then it works. But i need it to run a function.
And actually I don't need it to run the function with the header value in, I need the content between [template] and [/template] to be in the function.
Does anyone have any idea how to do this?
$replace[]be something like this?$replace[] = array_map($double, "$1");, and then above it I should have this to run my function?$call_a_template = function($a) { $this->get($a); }