どのように preg_replace を同じクラスで関数を呼び出すことができますか?
私は次のことを試しました:
<?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;
}
}
}
しかし、それだけで次のエラーが発生します。
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@site.com 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.
私がこれをアウトコメントするとすぐに:
// Call a template
$pattern[] = "/\[template\](.*?)\[\/template\]/is";
$replace[] = $this->get('header');
その後、動作します。しかし、関数を実行するにはそれが必要です。
そして実際には、値を入れて関数を実行する必要はありません。関数内にとheader
の間のコンテンツが必要です。[template]
[/template]
誰もこれを行う方法を知っていますか?