Thursday, 15 May 2014

php - Preg_replace call function in same class? -



php - Preg_replace call function in same class? -

how can preg_replace phone call function in same class?

i have tried 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` `main_templates` inner bring together `main_templates_group` on `main_templates_group`.`id` = `main_templates`.`gid` inner bring together `main_themes` on `main_themes`.`id` = `main_templates_group`.`tid` `main_themes`.`id` = '".$this->theme."' && `main_templates`.`name` = '".$template."' "); while ($templates = mysql_fetch_array($query)) { $content = $templates['content']; // outcomment $pattern[] = "/\/\*(.*?)\*\//is"; $replace[] = ""; // phone call template $pattern[] = "/\[template\](.*?)\[\/template\]/is"; $replace[] = $this->get('header'); $content = preg_replace($pattern, $replace, $content); homecoming $content; } } }

but comes out next error:

internal server error server encountered internal error or misconfiguration , unable finish request. please contact server administrator, webmaster@site.com , inform them of time error occurred, , might have done may have caused error. more info error may available in server error log. additionally, 404 not found error encountered while trying utilize errordocument handle request.

as outcomment this:

// phone call template $pattern[] = "/\[template\](.*?)\[\/template\]/is"; $replace[] = $this->get('header');

then works. need run function.

and don't need run function header value in, need content between [template] , [/template] in function.

does have thought how this?

i think script might entering infinite loop. if in function, you're calling this:

$replace[] = $this->get('header');

so in middle of call, you're pulling in header. executes exact same function pull in header, on , over, on , over. might want disable line when $template 'header':

while ($templates = mysql_fetch_array($query)) { $content = $templates['content']; // if header, stop here if ($template == 'header') homecoming $content; // rest of loop... }

if want perform regular expressions, add together after while loop:

if ($template == 'header') { $pattern = "/\[template\](.*?)\[\/template\]/is"; $replace = 'whatever want replace with'; homecoming preg_replace($pattern, $replace, $templates['content']); }

php function object preg-replace

No comments:

Post a Comment